Skip to content

Commit

Permalink
for #1120, filter derived column for sharding-jdbc
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Aug 9, 2018
1 parent 18a8116 commit 3dd50bd
Show file tree
Hide file tree
Showing 24 changed files with 597 additions and 476 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package io.shardingsphere.core.jdbc.adapter;

import com.google.common.base.Preconditions;
import io.shardingsphere.core.jdbc.core.resultset.ShardingResultSetMetaData;
import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationResultSet;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -55,7 +56,7 @@ public AbstractResultSetAdapter(final List<ResultSet> resultSets, final Statemen

@Override
public final ResultSetMetaData getMetaData() throws SQLException {
return resultSets.get(0).getMetaData();
return new ShardingResultSetMetaData(resultSets.get(0).getMetaData());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.sql.Types;

/**
* ResultSet metadata for generated keys.
* Result set meta data for generated keys.
*
* @author gaohongtao
*/
Expand Down
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);
}
}
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>
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@
<metadata>
<column name="orders_avg" />
<column name="user_id" />
<column name="AVG_DERIVED_COUNT_0" />
<column name="AVG_DERIVED_SUM_0" />
</metadata>
<row values="1000.5000, 10, 2, 2001" />
<row values="1100.5000, 11, 2, 2201" />
<row values="1200.5000, 12, 2, 2401" />
<row values="1300.5000, 13, 2, 2601" />
<row values="1400.5000, 14, 2, 2801" />
<row values="1500.5000, 15, 2, 3001" />
<row values="1600.5000, 16, 2, 3201" />
<row values="1700.5000, 17, 2, 3401" />
<row values="1800.5000, 18, 2, 3601" />
<row values="1900.5000, 19, 2, 3801" />
<row values="2000.5000, 20, 2, 4001" />
<row values="2100.5000, 21, 2, 4201" />
<row values="2200.5000, 22, 2, 4401" />
<row values="2300.5000, 23, 2, 4601" />
<row values="2400.5000, 24, 2, 4801" />
<row values="2500.5000, 25, 2, 5001" />
<row values="2600.5000, 26, 2, 5201" />
<row values="2700.5000, 27, 2, 5401" />
<row values="2800.5000, 28, 2, 5601" />
<row values="2900.5000, 29, 2, 5801" />
<row values="1000.5000, 10" />
<row values="1100.5000, 11" />
<row values="1200.5000, 12" />
<row values="1300.5000, 13" />
<row values="1400.5000, 14" />
<row values="1500.5000, 15" />
<row values="1600.5000, 16" />
<row values="1700.5000, 17" />
<row values="1800.5000, 18" />
<row values="1900.5000, 19" />
<row values="2000.5000, 20" />
<row values="2100.5000, 21" />
<row values="2200.5000, 22" />
<row values="2300.5000, 23" />
<row values="2400.5000, 24" />
<row values="2500.5000, 25" />
<row values="2600.5000, 26" />
<row values="2700.5000, 27" />
<row values="2800.5000, 28" />
<row values="2900.5000, 29" />
</dataset>
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>
Loading

0 comments on commit 3dd50bd

Please sign in to comment.