-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
for #1120, filter derived column for sharding-jdbc
- Loading branch information
Showing
24 changed files
with
597 additions
and
476 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
...c/src/main/java/io/shardingsphere/core/jdbc/core/resultset/ShardingResultSetMetaData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* | ||
* Copyright 2016-2018 shardingsphere.io. | ||
* <p> | ||
* Licensed 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. | ||
* </p> | ||
*/ | ||
|
||
package io.shardingsphere.core.jdbc.core.resultset; | ||
|
||
import io.shardingsphere.core.jdbc.adapter.WrapperAdapter; | ||
import io.shardingsphere.core.parsing.parser.constant.DerivedColumn; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.sql.ResultSetMetaData; | ||
import java.sql.SQLException; | ||
|
||
/** | ||
* Sharding result set meta data. | ||
* | ||
* @author zhangliang | ||
*/ | ||
@RequiredArgsConstructor | ||
public final class ShardingResultSetMetaData extends WrapperAdapter implements ResultSetMetaData { | ||
|
||
private final ResultSetMetaData resultSetMetaData; | ||
|
||
@Override | ||
public int getColumnCount() throws SQLException { | ||
int result = 0; | ||
for (int columnIndex = 1; columnIndex <= resultSetMetaData.getColumnCount(); columnIndex++) { | ||
if (!DerivedColumn.isDerivedColumn(resultSetMetaData.getColumnLabel(columnIndex))) { | ||
result++; | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean isAutoIncrement(final int column) throws SQLException { | ||
return resultSetMetaData.isAutoIncrement(column); | ||
} | ||
|
||
@Override | ||
public boolean isCaseSensitive(final int column) throws SQLException { | ||
return resultSetMetaData.isCaseSensitive(column); | ||
} | ||
|
||
@Override | ||
public boolean isSearchable(final int column) throws SQLException { | ||
return resultSetMetaData.isSearchable(column); | ||
} | ||
|
||
@Override | ||
public boolean isCurrency(final int column) throws SQLException { | ||
return resultSetMetaData.isCurrency(column); | ||
} | ||
|
||
@Override | ||
public int isNullable(final int column) throws SQLException { | ||
return resultSetMetaData.isNullable(column); | ||
} | ||
|
||
@Override | ||
public boolean isSigned(final int column) throws SQLException { | ||
return resultSetMetaData.isSigned(column); | ||
} | ||
|
||
@Override | ||
public int getColumnDisplaySize(final int column) throws SQLException { | ||
return resultSetMetaData.getColumnDisplaySize(column); | ||
} | ||
|
||
@Override | ||
public String getColumnLabel(final int column) throws SQLException { | ||
return resultSetMetaData.getColumnLabel(column); | ||
} | ||
|
||
@Override | ||
public String getColumnName(final int column) throws SQLException { | ||
return resultSetMetaData.getColumnName(column); | ||
} | ||
|
||
@Override | ||
public String getSchemaName(final int column) throws SQLException { | ||
return resultSetMetaData.getSchemaName(column); | ||
} | ||
|
||
@Override | ||
public int getPrecision(final int column) throws SQLException { | ||
return resultSetMetaData.getPrecision(column); | ||
} | ||
|
||
@Override | ||
public int getScale(final int column) throws SQLException { | ||
return resultSetMetaData.getScale(column); | ||
} | ||
|
||
@Override | ||
public String getTableName(final int column) throws SQLException { | ||
return resultSetMetaData.getTableName(column); | ||
} | ||
|
||
@Override | ||
public String getCatalogName(final int column) throws SQLException { | ||
return resultSetMetaData.getCatalogName(column); | ||
} | ||
|
||
@Override | ||
public int getColumnType(final int column) throws SQLException { | ||
return resultSetMetaData.getColumnType(column); | ||
} | ||
|
||
@Override | ||
public String getColumnTypeName(final int column) throws SQLException { | ||
return resultSetMetaData.getColumnTypeName(column); | ||
} | ||
|
||
@Override | ||
public boolean isReadOnly(final int column) throws SQLException { | ||
return resultSetMetaData.isReadOnly(column); | ||
} | ||
|
||
@Override | ||
public boolean isWritable(final int column) throws SQLException { | ||
return resultSetMetaData.isWritable(column); | ||
} | ||
|
||
@Override | ||
public boolean isDefinitelyWritable(final int column) throws SQLException { | ||
return resultSetMetaData.isDefinitelyWritable(column); | ||
} | ||
|
||
@Override | ||
public String getColumnClassName(final int column) throws SQLException { | ||
return resultSetMetaData.getColumnClassName(column); | ||
} | ||
} |
4 changes: 1 addition & 3 deletions
4
sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_avg.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
<dataset> | ||
<metadata> | ||
<column name="user_id_avg" /> | ||
<column name="AVG_DERIVED_COUNT_0" /> | ||
<column name="AVG_DERIVED_SUM_0" /> | ||
</metadata> | ||
<row values="19.5000, 40, 780" /> | ||
<row values="19.5000" /> | ||
</dataset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
...rc/test/resources/asserts/cases/dql/dataset/db/select_group_by_without_grouped_column.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
<dataset> | ||
<metadata> | ||
<column name="items_count" /> | ||
<column name="GROUP_BY_DERIVED_0" /> | ||
</metadata> | ||
<row values="4, 10" /> | ||
<row values="4, 11" /> | ||
<row values="4" /> | ||
<row values="4" /> | ||
</dataset> |
Oops, something went wrong.