This is an automated email from the ASF dual-hosted git repository. lujingshang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push: new fb489269270 15827 (#17434) fb489269270 is described below commit fb489269270ea621ad7e454284d9990c5eaaa8ff Author: boyjoy1127 <101028753+boyjoy1...@users.noreply.github.com> AuthorDate: Wed May 25 16:27:29 2022 +0800 15827 (#17434) * feat: add EunumerableMergedRsult class. * feat: add FederationResultSet. * style: fix code style problem. * test: add unit test. * fix: cost unequal problem. * fix: unit test bugs. * fix: unit test bugs. * fix: unit test bugs. * fix: unit test bugs. --- pom.xml | 6 +- .../pom.xml | 36 ++ .../AbstractUnsupportedOperationResultSet.java | 212 ++++++++++ ...bstractUnsupportedUpdateOperationResultSet.java | 451 +++++++++++++++++++++ .../customized/CustomizedFilterableExecutor.java | 23 +- .../executor/customized/FederationResultSet.java | 399 ++++++++++++++++++ .../executor/customized/WrapperAdapter.java | 41 ++ .../CustomizedFilterableExecutorTest.java | 100 +++++ .../customized/fixture/CommonFixtureRule.java | 36 ++ ...chema.builder.spi.RuleBasedTableMetaDataBuilder | 18 + .../src/test/resources/logback-test.xml | 33 ++ .../shardingsphere-infra-merge/pom.xml | 4 + .../impl/enumerable/EnumerableMergedResult.java | 81 ++++ 13 files changed, 1436 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 45c6e8bbdcd..55bcb509125 100644 --- a/pom.xml +++ b/pom.xml @@ -322,7 +322,11 @@ <classifier>linux-aarch_64</classifier> <scope>runtime</scope> </dependency> - + <dependency> + <groupId>org.apache.calcite</groupId> + <artifactId>calcite-linq4j</artifactId> + <version>${calcite.version}</version> + </dependency> <dependency> <groupId>javax.transaction</groupId> <artifactId>jta</artifactId> diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/pom.xml b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/pom.xml index 6aa15896786..71984dffbef 100644 --- a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/pom.xml +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/pom.xml @@ -48,5 +48,41 @@ <artifactId>shardingsphere-infra-merge</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.shardingsphere</groupId> + <artifactId>shardingsphere-sql-parser-sql92</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.shardingsphere</groupId> + <artifactId>shardingsphere-sql-parser-mysql</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.shardingsphere</groupId> + <artifactId>shardingsphere-sql-parser-postgresql</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.shardingsphere</groupId> + <artifactId>shardingsphere-sql-parser-oracle</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.shardingsphere</groupId> + <artifactId>shardingsphere-sql-parser-sqlserver</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.shardingsphere</groupId> + <artifactId>shardingsphere-sql-parser-opengauss</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/customized/AbstractUnsupportedOperationResultSet.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/customized/AbstractUnsupportedOperationResultSet.java new file mode 100644 index 00000000000..c4ad246a279 --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/customized/AbstractUnsupportedOperationResultSet.java @@ -0,0 +1,212 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.federation.executor.customized; + +import java.io.Reader; +import java.sql.NClob; +import java.sql.Ref; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.util.Map; + +/** + * Unsupported {@code ResultSet} methods. + */ +public abstract class AbstractUnsupportedOperationResultSet extends AbstractUnsupportedUpdateOperationResultSet { + + @Override + public boolean previous() throws SQLException { + throw new SQLFeatureNotSupportedException("previous"); + } + + @Override + public boolean isBeforeFirst() throws SQLException { + throw new SQLFeatureNotSupportedException("isBeforeFirst"); + } + + @Override + public boolean isAfterLast() throws SQLException { + throw new SQLFeatureNotSupportedException("isAfterLast"); + } + + @Override + public boolean isFirst() throws SQLException { + throw new SQLFeatureNotSupportedException("isFirst"); + } + + @Override + public boolean isLast() throws SQLException { + throw new SQLFeatureNotSupportedException("isLast"); + } + + @Override + public void beforeFirst() throws SQLException { + throw new SQLFeatureNotSupportedException("beforeFirst"); + } + + @Override + public void afterLast() throws SQLException { + throw new SQLFeatureNotSupportedException("afterLast"); + } + + @Override + public boolean first() throws SQLException { + throw new SQLFeatureNotSupportedException("first"); + } + + @Override + public boolean last() throws SQLException { + throw new SQLFeatureNotSupportedException("last"); + } + + @Override + public boolean absolute(final int row) throws SQLException { + throw new SQLFeatureNotSupportedException("absolute"); + } + + @Override + public boolean relative(final int rows) throws SQLException { + throw new SQLFeatureNotSupportedException("relative"); + } + + @Override + public int getRow() throws SQLException { + throw new SQLFeatureNotSupportedException("getRow"); + } + + @Override + public final void insertRow() throws SQLException { + throw new SQLFeatureNotSupportedException("insertRow"); + } + + @Override + public final void updateRow() throws SQLException { + throw new SQLFeatureNotSupportedException("updateRow"); + } + + @Override + public final void deleteRow() throws SQLException { + throw new SQLFeatureNotSupportedException("deleteRow"); + } + + @Override + public final void refreshRow() throws SQLException { + throw new SQLFeatureNotSupportedException("refreshRow"); + } + + @Override + public final void cancelRowUpdates() throws SQLException { + throw new SQLFeatureNotSupportedException("cancelRowUpdates"); + } + + @Override + public final void moveToInsertRow() throws SQLException { + throw new SQLFeatureNotSupportedException("moveToInsertRow"); + } + + @Override + public final void moveToCurrentRow() throws SQLException { + throw new SQLFeatureNotSupportedException("moveToCurrentRow"); + } + + @Override + public final boolean rowInserted() throws SQLException { + throw new SQLFeatureNotSupportedException("rowInserted"); + } + + @Override + public final boolean rowUpdated() throws SQLException { + throw new SQLFeatureNotSupportedException("rowUpdated"); + } + + @Override + public final boolean rowDeleted() throws SQLException { + throw new SQLFeatureNotSupportedException("rowDeleted"); + } + + @Override + public final String getCursorName() throws SQLException { + throw new SQLFeatureNotSupportedException("getCursorName"); + } + + @Override + public final int getHoldability() throws SQLException { + throw new SQLFeatureNotSupportedException("getHoldability"); + } + + @Override + public final NClob getNClob(final int columnIndex) throws SQLException { + throw new SQLFeatureNotSupportedException("getNClob"); + } + + @Override + public final NClob getNClob(final String columnLabel) throws SQLException { + throw new SQLFeatureNotSupportedException("getNClob"); + } + + @Override + public final Reader getNCharacterStream(final int columnIndex) throws SQLException { + throw new SQLFeatureNotSupportedException("getNCharacterStream"); + } + + @Override + public final Reader getNCharacterStream(final String columnLabel) throws SQLException { + throw new SQLFeatureNotSupportedException("getNCharacterStream"); + } + + @Override + public final Ref getRef(final int columnIndex) throws SQLException { + throw new SQLFeatureNotSupportedException("getRef"); + } + + @Override + public final Ref getRef(final String columnLabel) throws SQLException { + throw new SQLFeatureNotSupportedException("getRef"); + } + + @Override + public final RowId getRowId(final int columnIndex) throws SQLException { + throw new SQLFeatureNotSupportedException("getRowId"); + } + + @Override + public final RowId getRowId(final String columnLabel) throws SQLException { + throw new SQLFeatureNotSupportedException("getRowId"); + } + + @Override + public <T> T getObject(final int columnIndex, final Class<T> type) throws SQLException { + throw new SQLFeatureNotSupportedException("getObject with type"); + } + + @Override + public <T> T getObject(final String columnLabel, final Class<T> type) throws SQLException { + throw new SQLFeatureNotSupportedException("getObject with type"); + } + + @Override + public final Object getObject(final String columnLabel, final Map<String, Class<?>> map) throws SQLException { + throw new SQLFeatureNotSupportedException("getObject with map"); + } + + @Override + public final Object getObject(final int columnIndex, final Map<String, Class<?>> map) throws SQLException { + throw new SQLFeatureNotSupportedException("getObject with map"); + } +} diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/customized/AbstractUnsupportedUpdateOperationResultSet.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/customized/AbstractUnsupportedUpdateOperationResultSet.java new file mode 100644 index 00000000000..7784d57c8ae --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/customized/AbstractUnsupportedUpdateOperationResultSet.java @@ -0,0 +1,451 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.federation.executor.customized; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.SQLXML; +import java.sql.Time; +import java.sql.Timestamp; + +/** + * Unsupported {@code ResultSet} methods. + */ +public abstract class AbstractUnsupportedUpdateOperationResultSet extends WrapperAdapter implements ResultSet { + + @Override + public final void updateNull(final int columnIndex) throws SQLException { + throw new SQLFeatureNotSupportedException("updateNull"); + } + + @Override + public final void updateNull(final String columnLabel) throws SQLException { + throw new SQLFeatureNotSupportedException("updateNull"); + } + + @Override + public final void updateBoolean(final int columnIndex, final boolean x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBoolean"); + } + + @Override + public final void updateBoolean(final String columnLabel, final boolean x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBoolean"); + } + + @Override + public final void updateByte(final int columnIndex, final byte x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateByte"); + } + + @Override + public final void updateByte(final String columnLabel, final byte x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateByte"); + } + + @Override + public final void updateShort(final int columnIndex, final short x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateShort"); + } + + @Override + public final void updateShort(final String columnLabel, final short x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateShort"); + } + + @Override + public final void updateInt(final int columnIndex, final int x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateInt"); + } + + @Override + public final void updateInt(final String columnLabel, final int x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateInt"); + } + + @Override + public final void updateLong(final int columnIndex, final long x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateLong"); + } + + @Override + public final void updateLong(final String columnLabel, final long x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateLong"); + } + + @Override + public final void updateFloat(final int columnIndex, final float x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateFloat"); + } + + @Override + public final void updateFloat(final String columnLabel, final float x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateFloat"); + } + + @Override + public final void updateDouble(final int columnIndex, final double x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateDouble"); + } + + @Override + public final void updateDouble(final String columnLabel, final double x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateDouble"); + } + + @Override + public final void updateBigDecimal(final int columnIndex, final BigDecimal x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBigDecimal"); + } + + @Override + public final void updateBigDecimal(final String columnLabel, final BigDecimal x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBigDecimal"); + } + + @Override + public final void updateString(final int columnIndex, final String x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateString"); + } + + @Override + public final void updateString(final String columnLabel, final String x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateString"); + } + + @Override + public final void updateNString(final int columnIndex, final String nString) throws SQLException { + throw new SQLFeatureNotSupportedException("updateNString"); + } + + @Override + public final void updateNString(final String columnLabel, final String nString) throws SQLException { + throw new SQLFeatureNotSupportedException("updateNString"); + } + + @Override + public final void updateBytes(final int columnIndex, final byte[] x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBytes"); + } + + @Override + public final void updateBytes(final String columnLabel, final byte[] x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBytes"); + } + + @Override + public final void updateDate(final int columnIndex, final Date x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateDate"); + } + + @Override + public final void updateDate(final String columnLabel, final Date x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateDate"); + } + + @Override + public final void updateTime(final int columnIndex, final Time x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateTime"); + } + + @Override + public final void updateTime(final String columnLabel, final Time x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateTime"); + } + + @Override + public final void updateTimestamp(final int columnIndex, final Timestamp x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateTimestamp"); + } + + @Override + public final void updateTimestamp(final String columnLabel, final Timestamp x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateTimestamp"); + } + + @Override + public final void updateAsciiStream(final int columnIndex, final InputStream inputStream) throws SQLException { + throw new SQLFeatureNotSupportedException("updateAsciiStream"); + } + + @Override + public final void updateAsciiStream(final String columnLabel, final InputStream inputStream) throws SQLException { + throw new SQLFeatureNotSupportedException("updateAsciiStream"); + } + + @Override + public final void updateAsciiStream(final int columnIndex, final InputStream x, final int length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateAsciiStream"); + } + + @Override + public final void updateAsciiStream(final String columnLabel, final InputStream x, final int length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateAsciiStream"); + } + + @Override + public final void updateAsciiStream(final int columnIndex, final InputStream inputStream, final long length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateAsciiStream"); + } + + @Override + public final void updateAsciiStream(final String columnLabel, final InputStream inputStream, final long length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateAsciiStream"); + } + + @Override + public final void updateBinaryStream(final int columnIndex, final InputStream x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBinaryStream"); + } + + @Override + public final void updateBinaryStream(final String columnLabel, final InputStream x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBinaryStream"); + } + + @Override + public final void updateBinaryStream(final int columnIndex, final InputStream x, final int length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBinaryStream"); + } + + @Override + public final void updateBinaryStream(final String columnLabel, final InputStream x, final int length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBinaryStream"); + } + + @Override + public final void updateBinaryStream(final int columnIndex, final InputStream x, final long length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBinaryStream"); + } + + @Override + public final void updateBinaryStream(final String columnLabel, final InputStream x, final long length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBinaryStream"); + } + + @Override + public final void updateCharacterStream(final int columnIndex, final Reader x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateCharacterStream"); + } + + @Override + public final void updateCharacterStream(final String columnLabel, final Reader x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateCharacterStream"); + } + + @Override + public final void updateCharacterStream(final int columnIndex, final Reader x, final int length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateCharacterStream"); + } + + @Override + public final void updateCharacterStream(final String columnLabel, final Reader reader, final int length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateCharacterStream"); + } + + @Override + public final void updateCharacterStream(final int columnIndex, final Reader x, final long length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateCharacterStream"); + } + + @Override + public final void updateCharacterStream(final String columnLabel, final Reader reader, final long length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateCharacterStream"); + } + + @Override + public final void updateNCharacterStream(final int columnIndex, final Reader x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateNCharacterStream"); + } + + @Override + public final void updateNCharacterStream(final String columnLabel, final Reader x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateNCharacterStream"); + } + + @Override + public final void updateNCharacterStream(final int columnIndex, final Reader x, final long length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateNCharacterStream"); + } + + @Override + public final void updateNCharacterStream(final String columnLabel, final Reader x, final long length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateNCharacterStream"); + } + + @Override + public final void updateObject(final int columnIndex, final Object x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateObject"); + } + + @Override + public final void updateObject(final String columnLabel, final Object x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateObject"); + } + + @Override + public final void updateObject(final int columnIndex, final Object x, final int scaleOrLength) throws SQLException { + throw new SQLFeatureNotSupportedException("updateObject"); + } + + @Override + public final void updateObject(final String columnLabel, final Object x, final int scaleOrLength) throws SQLException { + throw new SQLFeatureNotSupportedException("updateObject"); + } + + @Override + public final void updateRef(final int columnIndex, final Ref x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateRef"); + } + + @Override + public final void updateRef(final String columnLabel, final Ref x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateRef"); + } + + @Override + public final void updateBlob(final int columnIndex, final Blob x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBlob"); + } + + @Override + public final void updateBlob(final String columnLabel, final Blob x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBlob"); + } + + @Override + public final void updateBlob(final int columnIndex, final InputStream inputStream) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBlob"); + } + + @Override + public final void updateBlob(final String columnLabel, final InputStream inputStream) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBlob"); + } + + @Override + public final void updateBlob(final int columnIndex, final InputStream inputStream, final long length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBlob"); + } + + @Override + public final void updateBlob(final String columnLabel, final InputStream inputStream, final long length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateBlob"); + } + + @Override + public final void updateClob(final int columnIndex, final Clob x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateClob"); + } + + @Override + public final void updateClob(final String columnLabel, final Clob x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateClob"); + } + + @Override + public final void updateClob(final int columnIndex, final Reader reader) throws SQLException { + throw new SQLFeatureNotSupportedException("updateClob"); + } + + @Override + public final void updateClob(final String columnLabel, final Reader reader) throws SQLException { + throw new SQLFeatureNotSupportedException("updateClob"); + } + + @Override + public final void updateClob(final int columnIndex, final Reader reader, final long length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateClob"); + } + + @Override + public final void updateClob(final String columnLabel, final Reader reader, final long length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateClob"); + } + + @Override + public final void updateNClob(final int columnIndex, final NClob nClob) throws SQLException { + throw new SQLFeatureNotSupportedException("updateNClob"); + } + + @Override + public final void updateNClob(final String columnLabel, final NClob nClob) throws SQLException { + throw new SQLFeatureNotSupportedException("updateNClob"); + } + + @Override + public final void updateNClob(final int columnIndex, final Reader reader) throws SQLException { + throw new SQLFeatureNotSupportedException("updateNClob"); + } + + @Override + public final void updateNClob(final String columnLabel, final Reader reader) throws SQLException { + throw new SQLFeatureNotSupportedException("updateNClob"); + } + + @Override + public final void updateNClob(final int columnIndex, final Reader reader, final long length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateNClob"); + } + + @Override + public final void updateNClob(final String columnLabel, final Reader reader, final long length) throws SQLException { + throw new SQLFeatureNotSupportedException("updateNClob"); + } + + @Override + public final void updateArray(final int columnIndex, final Array x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateArray"); + } + + @Override + public final void updateArray(final String columnLabel, final Array x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateArray"); + } + + @Override + public final void updateRowId(final int columnIndex, final RowId x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateRowId"); + } + + @Override + public final void updateRowId(final String columnLabel, final RowId x) throws SQLException { + throw new SQLFeatureNotSupportedException("updateRowId"); + } + + @Override + public final void updateSQLXML(final int columnIndex, final SQLXML xmlObject) throws SQLException { + throw new SQLFeatureNotSupportedException("updateSQLXML"); + } + + @Override + public final void updateSQLXML(final String columnLabel, final SQLXML xmlObject) throws SQLException { + throw new SQLFeatureNotSupportedException("updateSQLXML"); + } +} diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/customized/CustomizedFilterableExecutor.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/customized/CustomizedFilterableExecutor.java index 792a3dbaec4..3db69908137 100644 --- a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/customized/CustomizedFilterableExecutor.java +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/customized/CustomizedFilterableExecutor.java @@ -23,6 +23,8 @@ import org.apache.calcite.linq4j.Enumerable; import org.apache.calcite.plan.RelOptCluster; import org.apache.calcite.plan.RelTraitSet; import org.apache.calcite.rel.RelNode; +import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine; +import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType; import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit; import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback; import org.apache.shardingsphere.infra.executor.sql.execute.result.ExecuteResult; @@ -31,6 +33,11 @@ import org.apache.shardingsphere.infra.federation.executor.FederationContext; import org.apache.shardingsphere.infra.federation.executor.FederationExecutor; import org.apache.shardingsphere.infra.federation.optimizer.ShardingSphereOptimizer; import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext; +import org.apache.shardingsphere.infra.merge.result.MergedResult; +import org.apache.shardingsphere.infra.merge.result.impl.enumerable.EnumerableMergedResult; +import org.apache.shardingsphere.infra.parser.ParserConfiguration; +import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine; +import org.apache.shardingsphere.sql.parser.api.CacheOption; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; import java.sql.Connection; @@ -48,6 +55,10 @@ public final class CustomizedFilterableExecutor implements FederationExecutor { private final ShardingSphereOptimizer optimizer; + private ResultSet federationResultSet; + + private final ParserConfiguration parserConfiguration = new ParserConfiguration(new CacheOption(1, 1), new CacheOption(1, 1), false); + public CustomizedFilterableExecutor(final String databaseName, final String schemaName, final OptimizerContext context) { this.databaseName = databaseName; this.schemaName = schemaName; @@ -57,13 +68,19 @@ public final class CustomizedFilterableExecutor implements FederationExecutor { @Override public ResultSet executeQuery(final DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> prepareEngine, final JDBCExecutorCallback<? extends ExecuteResult> callback, final FederationContext federationContext) throws SQLException { - // TODO - return null; + String sql = federationContext.getLogicSQL().getSql(); + ShardingSphereSQLParserEngine sqlParserEngine = new ShardingSphereSQLParserEngine( + DatabaseTypeEngine.getTrunkDatabaseTypeName(new H2DatabaseType()), parserConfiguration); + SQLStatement sqlStatement = sqlParserEngine.parse(sql, false); + Enumerable<Object[]> enumerableResult = execute(sqlStatement); + MergedResult mergedResult = new EnumerableMergedResult(enumerableResult); + federationResultSet = new FederationResultSet(mergedResult); + return federationResultSet; } @Override public ResultSet getResultSet() { - return null; + return federationResultSet; } private Enumerable<Object[]> execute(final SQLStatement sqlStatement) { diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/customized/FederationResultSet.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/customized/FederationResultSet.java new file mode 100644 index 00000000000..e30e51c6cb2 --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/customized/FederationResultSet.java @@ -0,0 +1,399 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.federation.executor.customized; + +import lombok.AllArgsConstructor; +import org.apache.shardingsphere.infra.merge.result.MergedResult; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Calendar; + +@AllArgsConstructor +public final class FederationResultSet extends AbstractUnsupportedOperationResultSet { + + private MergedResult mergedResult; + + @Override + public boolean next() throws SQLException { + return mergedResult.next(); + } + + @Override + public void close() throws SQLException { + + } + + @Override + public boolean wasNull() throws SQLException { + return false; + } + + @Override + public String getString(final int columnIndex) throws SQLException { + return null; + } + + @Override + public String getString(final String columnLabel) throws SQLException { + return null; + } + + @Override + public boolean getBoolean(final int columnIndex) throws SQLException { + return false; + } + + @Override + public boolean getBoolean(final String columnLabel) throws SQLException { + return false; + } + + @Override + public byte getByte(final int columnIndex) throws SQLException { + return 0; + } + + @Override + public byte getByte(final String columnLabel) throws SQLException { + return 0; + } + + @Override + public short getShort(final int columnIndex) throws SQLException { + return 0; + } + + @Override + public short getShort(final String columnLabel) throws SQLException { + return 0; + } + + @Override + public int getInt(final int columnIndex) throws SQLException { + return 0; + } + + @Override + public int getInt(final String columnLabel) throws SQLException { + return 0; + } + + @Override + public long getLong(final int columnIndex) throws SQLException { + return 0; + } + + @Override + public long getLong(final String columnLabel) throws SQLException { + return 0; + } + + @Override + public float getFloat(final int columnIndex) throws SQLException { + return 0; + } + + @Override + public float getFloat(final String columnLabel) throws SQLException { + return 0; + } + + @Override + public double getDouble(final int columnIndex) throws SQLException { + return 0; + } + + @Override + public double getDouble(final String columnLabel) throws SQLException { + return 0; + } + + @Override + public BigDecimal getBigDecimal(final int columnIndex, final int scale) throws SQLException { + return null; + } + + @Override + public BigDecimal getBigDecimal(final String columnLabel, final int scale) throws SQLException { + return null; + } + + @Override + public BigDecimal getBigDecimal(final int columnIndex) throws SQLException { + return null; + } + + @Override + public BigDecimal getBigDecimal(final String columnLabel) throws SQLException { + return null; + } + + @Override + public byte[] getBytes(final int columnIndex) throws SQLException { + return new byte[0]; + } + + @Override + public byte[] getBytes(final String columnLabel) throws SQLException { + return new byte[0]; + } + + @Override + public Date getDate(final int columnIndex) throws SQLException { + return null; + } + + @Override + public Date getDate(final String columnLabel) throws SQLException { + return null; + } + + @Override + public Date getDate(final int columnIndex, final Calendar cal) throws SQLException { + return null; + } + + @Override + public Date getDate(final String columnLabel, final Calendar cal) throws SQLException { + return null; + } + + @Override + public Time getTime(final int columnIndex) throws SQLException { + return null; + } + + @Override + public Time getTime(final String columnLabel) throws SQLException { + return null; + } + + @Override + public Time getTime(final int columnIndex, final Calendar cal) throws SQLException { + return null; + } + + @Override + public Time getTime(final String columnLabel, final Calendar cal) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(final int columnIndex) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(final String columnLabel) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(final int columnIndex, final Calendar cal) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(final String columnLabel, final Calendar cal) throws SQLException { + return null; + } + + @Override + public InputStream getAsciiStream(final int columnIndex) throws SQLException { + return null; + } + + @Override + public InputStream getAsciiStream(final String columnLabel) throws SQLException { + return null; + } + + @Override + public InputStream getUnicodeStream(final int columnIndex) throws SQLException { + return null; + } + + @Override + public InputStream getUnicodeStream(final String columnLabel) throws SQLException { + return null; + } + + @Override + public InputStream getBinaryStream(final int columnIndex) throws SQLException { + return null; + } + + @Override + public InputStream getBinaryStream(final String columnLabel) throws SQLException { + return null; + } + + @Override + public SQLWarning getWarnings() throws SQLException { + return null; + } + + @Override + public void clearWarnings() throws SQLException { + + } + + @Override + public ResultSetMetaData getMetaData() throws SQLException { + return null; + } + + @Override + public Object getObject(final int columnIndex) throws SQLException { + return null; + } + + @Override + public Object getObject(final String columnLabel) throws SQLException { + return null; + } + + @Override + public int findColumn(final String columnLabel) throws SQLException { + return 0; + } + + @Override + public Reader getCharacterStream(final int columnIndex) throws SQLException { + return null; + } + + @Override + public Reader getCharacterStream(final String columnLabel) throws SQLException { + return null; + } + + @Override + public void setFetchDirection(final int direction) throws SQLException { + + } + + @Override + public int getFetchDirection() throws SQLException { + return 0; + } + + @Override + public void setFetchSize(final int rows) throws SQLException { + + } + + @Override + public int getFetchSize() throws SQLException { + return 0; + } + + @Override + public int getType() throws SQLException { + return 0; + } + + @Override + public int getConcurrency() throws SQLException { + return 0; + } + + @Override + public Statement getStatement() throws SQLException { + return null; + } + + @Override + public Blob getBlob(final int columnIndex) throws SQLException { + return null; + } + + @Override + public Blob getBlob(final String columnLabel) throws SQLException { + return null; + } + + @Override + public Clob getClob(final int columnIndex) throws SQLException { + return null; + } + + @Override + public Clob getClob(final String columnLabel) throws SQLException { + return null; + } + + @Override + public Array getArray(final int columnIndex) throws SQLException { + return null; + } + + @Override + public Array getArray(final String columnLabel) throws SQLException { + return null; + } + + @Override + public URL getURL(final int columnIndex) throws SQLException { + return null; + } + + @Override + public URL getURL(final String columnLabel) throws SQLException { + return null; + } + + @Override + public boolean isClosed() throws SQLException { + return false; + } + + @Override + public SQLXML getSQLXML(final int columnIndex) throws SQLException { + return null; + } + + @Override + public SQLXML getSQLXML(final String columnLabel) throws SQLException { + return null; + } + + @Override + public String getNString(final int columnIndex) throws SQLException { + return null; + } + + @Override + public String getNString(final String columnLabel) throws SQLException { + return null; + } +} diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/customized/WrapperAdapter.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/customized/WrapperAdapter.java new file mode 100644 index 00000000000..c3eb60f2a54 --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/main/java/org/apache/shardingsphere/infra/federation/executor/customized/WrapperAdapter.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.federation.executor.customized; + +import java.sql.SQLException; +import java.sql.Wrapper; + +/** + * Adapter for {@code java.sql.Wrapper}. + */ +public abstract class WrapperAdapter implements Wrapper { + + @SuppressWarnings("unchecked") + @Override + public final <T> T unwrap(final Class<T> iface) throws SQLException { + if (isWrapperFor(iface)) { + return (T) this; + } + throw new SQLException(String.format("[%s] cannot be unwrapped as [%s]", getClass().getName(), iface.getName())); + } + + @Override + public final boolean isWrapperFor(final Class<?> iface) { + return iface.isInstance(this); + } +} diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/test/java/org/apache/shardingsphere/infra/federation/executor/customized/CustomizedFilterableExecutorTest.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/test/java/org/apache/shardingsphere/infra/federation/executor/customized/CustomizedFilterableExecutorTest.java new file mode 100644 index 00000000000..62b18a99233 --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/test/java/org/apache/shardingsphere/infra/federation/executor/customized/CustomizedFilterableExecutorTest.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.federation.executor.customized; + +import lombok.SneakyThrows; +import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType; +import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext; +import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContextFactory; +import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabase; +import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource; +import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData; +import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema; +import org.apache.shardingsphere.infra.metadata.schema.model.ColumnMetaData; +import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData; +import org.apache.shardingsphere.infra.rule.ShardingSphereRule; +import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration; +import org.apache.shardingsphere.parser.rule.SQLParserRule; +import org.apache.shardingsphere.sql.parser.api.CacheOption; +import org.junit.Before; +import org.junit.Test; + +import java.sql.Types; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class CustomizedFilterableExecutorTest { + + private static final String SELECT_WHERE_SINGLE_FIELD = + "SELECT user_id FROM t_user_info WHERE user_id = 12"; + + private CustomizedFilterableExecutor executor; + + @Before + public void init() throws Exception { + Map<String, TableMetaData> tableMetaDataMap = new HashMap<>(2, 1); + tableMetaDataMap.put("t_order_federate", createOrderTableMetaData()); + tableMetaDataMap.put("t_user_info", createUserInfoTableMetaData()); + String schemaName = "federate_jdbc"; + Map<String, ShardingSphereSchema> schemas = new HashMap<>(2, 1); + String databaseName = "database_name"; + schemas.put(databaseName, new ShardingSphereSchema(tableMetaDataMap)); + ShardingSphereDatabase metaData = new ShardingSphereDatabase(schemaName, new H2DatabaseType(), mockResource(), null, schemas); + OptimizerContext optimizerContext = OptimizerContextFactory.create(Collections.singletonMap(schemaName, metaData), createGlobalRuleMetaData()); + executor = new CustomizedFilterableExecutor(databaseName, schemaName, optimizerContext); + } + + private ShardingSphereRuleMetaData createGlobalRuleMetaData() { + Collection<ShardingSphereRule> rules = new LinkedList<>(); + CacheOption cacheOption = new CacheOption(128, 1024L); + rules.add(new SQLParserRule(new SQLParserRuleConfiguration(false, cacheOption, cacheOption))); + return new ShardingSphereRuleMetaData(Collections.emptyList(), rules); + } + + private ShardingSphereResource mockResource() { + ShardingSphereResource result = mock(ShardingSphereResource.class); + when(result.getDatabaseType()).thenReturn(new H2DatabaseType()); + return result; + } + + private TableMetaData createOrderTableMetaData() { + ColumnMetaData orderIdColumn = new ColumnMetaData("order_id", Types.VARCHAR, true, false, false); + ColumnMetaData userIdColumn = new ColumnMetaData("user_id", Types.VARCHAR, false, false, false); + ColumnMetaData statusColumn = new ColumnMetaData("status", Types.VARCHAR, false, false, false); + return new TableMetaData("t_order_federate", Arrays.asList(orderIdColumn, userIdColumn, statusColumn), Collections.emptyList(), Collections.emptyList()); + } + + private TableMetaData createUserInfoTableMetaData() { + ColumnMetaData userIdColumn = new ColumnMetaData("user_id", Types.VARCHAR, true, false, false); + ColumnMetaData informationColumn = new ColumnMetaData("information", Types.VARCHAR, false, false, false); + return new TableMetaData("t_user_info", Arrays.asList(userIdColumn, informationColumn), Collections.emptyList(), Collections.emptyList()); + } + + @Test + @SneakyThrows + public void assertSelectWhereSingleField() { + // TODO add executor.executeQuery() + } +} diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/test/java/org/apache/shardingsphere/infra/federation/executor/customized/fixture/CommonFixtureRule.java b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/test/java/org/apache/shardingsphere/infra/federation/executor/customized/fixture/CommonFixtureRule.java new file mode 100644 index 00000000000..34a4bd43bc2 --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/test/java/org/apache/shardingsphere/infra/federation/executor/customized/fixture/CommonFixtureRule.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.federation.executor.customized.fixture; + +import org.apache.shardingsphere.infra.rule.identifier.type.TableContainedRule; + +import java.util.Collection; +import java.util.Collections; + +public final class CommonFixtureRule implements TableContainedRule { + + @Override + public Collection<String> getTables() { + return Collections.singletonList("t_order_new"); + } + + @Override + public String getType() { + return CommonFixtureRule.class.getSimpleName(); + } +} diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/test/resources/META-INF.services/org.apache.shardingsphere.infra.metadata.schema.builder.spi.RuleBasedTableMetaDataBuilder b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/test/resources/META-INF.services/org.apache.shardingsphere.infra.metadata.schema.builder.spi.RuleBasedTableMetaDataBuilder new file mode 100644 index 00000000000..a58cf11ad21 --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/test/resources/META-INF.services/org.apache.shardingsphere.infra.metadata.schema.builder.spi.RuleBasedTableMetaDataBuilder @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +org.apache.shardingsphere.infra.federation.optimizer.metadata.fixture.CommonFixtureTableMetaDataBuilder diff --git a/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/test/resources/logback-test.xml b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/test/resources/logback-test.xml new file mode 100644 index 00000000000..d90fc4a7156 --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-federation/shardingsphere-infra-federation-executor/src/test/resources/logback-test.xml @@ -0,0 +1,33 @@ +<?xml version="1.0"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<configuration> + <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n</pattern> + </encoder> + </appender> + <logger name="org.apache.shardingsphere" level="warn" additivity="false"> + <appender-ref ref="console" /> + </logger> + + <root> + <level value="error" /> + <appender-ref ref="console" /> + </root> +</configuration> diff --git a/shardingsphere-infra/shardingsphere-infra-merge/pom.xml b/shardingsphere-infra/shardingsphere-infra-merge/pom.xml index 93a966b4ed8..d8ea9ba0691 100644 --- a/shardingsphere-infra/shardingsphere-infra-merge/pom.xml +++ b/shardingsphere-infra/shardingsphere-infra-merge/pom.xml @@ -38,5 +38,9 @@ <artifactId>shardingsphere-infra-executor</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.calcite</groupId> + <artifactId>calcite-linq4j</artifactId> + </dependency> </dependencies> </project> diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/enumerable/EnumerableMergedResult.java b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/enumerable/EnumerableMergedResult.java new file mode 100644 index 00000000000..ba58d4888df --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/enumerable/EnumerableMergedResult.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.merge.result.impl.enumerable; + +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import org.apache.calcite.linq4j.Enumerable; +import org.apache.shardingsphere.infra.merge.result.MergedResult; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectOutputStream; +import java.sql.SQLException; +import java.util.Calendar; + +/** + * Enumerable merged result. + */ +@RequiredArgsConstructor +public final class EnumerableMergedResult implements MergedResult { + + private final Enumerable<Object[]> enumerableResult; + + private boolean wasNull; + + @Override + public boolean next() throws SQLException { + return enumerableResult.enumerator().moveNext(); + } + + @Override + public Object getValue(final int columnIndex, final Class<?> type) throws SQLException { + Object result = enumerableResult.enumerator().current()[columnIndex - 1]; + wasNull = null == result; + return result; + } + + @Override + public Object getCalendarValue(final int columnIndex, final Class<?> type, final Calendar calendar) throws SQLException { + Object result = enumerableResult.enumerator().current()[columnIndex - 1]; + wasNull = null == result; + return result; + } + + @Override + public InputStream getInputStream(final int columnIndex, final String type) throws SQLException { + return getInputStream(enumerableResult.enumerator().current()[columnIndex - 1]); + } + + @SneakyThrows(IOException.class) + private InputStream getInputStream(final Object value) { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); + objectOutputStream.writeObject(value); + objectOutputStream.flush(); + objectOutputStream.close(); + return new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); + } + + @Override + public boolean wasNull() throws SQLException { + return wasNull; + } +}