mirror of https://github.com/apache/lucene.git
SOLR-8250: Implement ResultSetMetaDataImpl getColumnLabel(int column) and getColumnDisplaySize(int column)
This commit is contained in:
parent
6acfa2a4ff
commit
eb6bf9bc54
|
@ -128,67 +128,67 @@ class ResultSetImpl implements ResultSet {
|
|||
|
||||
@Override
|
||||
public String getString(int columnIndex) throws SQLException {
|
||||
return this.getString(this.resultSetMetaData.getColumnName(columnIndex));
|
||||
return this.getString(this.resultSetMetaData.getColumnLabel(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(int columnIndex) throws SQLException {
|
||||
return this.getBoolean(this.resultSetMetaData.getColumnName(columnIndex));
|
||||
return this.getBoolean(this.resultSetMetaData.getColumnLabel(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getByte(int columnIndex) throws SQLException {
|
||||
return this.getByte(this.resultSetMetaData.getColumnName(columnIndex));
|
||||
return this.getByte(this.resultSetMetaData.getColumnLabel(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getShort(int columnIndex) throws SQLException {
|
||||
return this.getShort(this.resultSetMetaData.getColumnName(columnIndex));
|
||||
return this.getShort(this.resultSetMetaData.getColumnLabel(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(int columnIndex) throws SQLException {
|
||||
return this.getInt(this.resultSetMetaData.getColumnName(columnIndex));
|
||||
return this.getInt(this.resultSetMetaData.getColumnLabel(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLong(int columnIndex) throws SQLException {
|
||||
return this.getLong(this.resultSetMetaData.getColumnName(columnIndex));
|
||||
return this.getLong(this.resultSetMetaData.getColumnLabel(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFloat(int columnIndex) throws SQLException {
|
||||
return this.getFloat(this.resultSetMetaData.getColumnName(columnIndex));
|
||||
return this.getFloat(this.resultSetMetaData.getColumnLabel(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDouble(int columnIndex) throws SQLException {
|
||||
return this.getDouble(this.resultSetMetaData.getColumnName(columnIndex));
|
||||
return this.getDouble(this.resultSetMetaData.getColumnLabel(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
|
||||
return this.getBigDecimal(this.resultSetMetaData.getColumnName(columnIndex), scale);
|
||||
return this.getBigDecimal(this.resultSetMetaData.getColumnLabel(columnIndex), scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBytes(int columnIndex) throws SQLException {
|
||||
return this.getBytes(this.resultSetMetaData.getColumnName(columnIndex));
|
||||
return this.getBytes(this.resultSetMetaData.getColumnLabel(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getDate(int columnIndex) throws SQLException {
|
||||
return this.getDate(this.resultSetMetaData.getColumnName(columnIndex));
|
||||
return this.getDate(this.resultSetMetaData.getColumnLabel(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Time getTime(int columnIndex) throws SQLException {
|
||||
return this.getTime(this.resultSetMetaData.getColumnName(columnIndex));
|
||||
return this.getTime(this.resultSetMetaData.getColumnLabel(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp getTimestamp(int columnIndex) throws SQLException {
|
||||
return this.getTimestamp(this.resultSetMetaData.getColumnName(columnIndex));
|
||||
return this.getTimestamp(this.resultSetMetaData.getColumnLabel(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -371,7 +371,7 @@ class ResultSetImpl implements ResultSet {
|
|||
|
||||
@Override
|
||||
public Object getObject(int columnIndex) throws SQLException {
|
||||
return this.getObject(this.resultSetMetaData.getColumnName(columnIndex));
|
||||
return this.getObject(this.resultSetMetaData.getColumnLabel(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.sql.ResultSetMetaData;
|
|||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.solr.client.solrj.io.Tuple;
|
||||
|
||||
|
@ -36,7 +37,7 @@ class ResultSetMetaDataImpl implements ResultSetMetaData {
|
|||
}
|
||||
|
||||
private Class getColumnClass(int column) throws SQLException {
|
||||
Object o = this.firstTuple.get(this.getColumnName(column));
|
||||
Object o = this.firstTuple.get(this.getColumnLabel(column));
|
||||
if(o == null) {
|
||||
return String.class; //Nulls will only be present with Strings.
|
||||
} else {
|
||||
|
@ -85,12 +86,13 @@ class ResultSetMetaDataImpl implements ResultSetMetaData {
|
|||
|
||||
@Override
|
||||
public int getColumnDisplaySize(int column) throws SQLException {
|
||||
return 0;
|
||||
return this.getColumnLabel(column).length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnLabel(int column) throws SQLException {
|
||||
return null;
|
||||
Map<String, String> aliases = (Map<String, String>) metadataTuple.get("aliases");
|
||||
return aliases.get(this.getColumnName(column));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -357,7 +357,7 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
|
|||
String collection = DEFAULT_COLLECTION;
|
||||
String connectionString = "jdbc:solr://" + zkServer.getZkAddress() + "?collection=" + collection +
|
||||
"&username=&password=&testKey1=testValue&testKey2";
|
||||
String sql = "select id, a_i, a_s, a_f from " + collection + " order by a_i desc limit 2";
|
||||
String sql = "select id, a_i, a_s, a_f as my_float_col from " + collection + " order by a_i desc limit 2";
|
||||
|
||||
try (Connection con = DriverManager.getConnection(connectionString)) {
|
||||
assertEquals(collection, con.getCatalog());
|
||||
|
@ -405,6 +405,21 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
|
|||
|
||||
assertEquals(4, resultSetMetaData.getColumnCount());
|
||||
|
||||
assertEquals("id", resultSetMetaData.getColumnName(1));
|
||||
assertEquals("a_i", resultSetMetaData.getColumnName(2));
|
||||
assertEquals("a_s", resultSetMetaData.getColumnName(3));
|
||||
assertEquals("a_f", resultSetMetaData.getColumnName(4));
|
||||
|
||||
assertEquals("id", resultSetMetaData.getColumnLabel(1));
|
||||
assertEquals("a_i", resultSetMetaData.getColumnLabel(2));
|
||||
assertEquals("a_s", resultSetMetaData.getColumnLabel(3));
|
||||
assertEquals("my_float_col", resultSetMetaData.getColumnLabel(4));
|
||||
|
||||
assertEquals("id".length(), resultSetMetaData.getColumnDisplaySize(1));
|
||||
assertEquals("a_i".length(), resultSetMetaData.getColumnDisplaySize(2));
|
||||
assertEquals("a_s".length(), resultSetMetaData.getColumnDisplaySize(3));
|
||||
assertEquals("my_float_col".length(), resultSetMetaData.getColumnDisplaySize(4));
|
||||
|
||||
assertEquals("Long", resultSetMetaData.getColumnTypeName(1));
|
||||
assertEquals("Long", resultSetMetaData.getColumnTypeName(2));
|
||||
assertEquals("String", resultSetMetaData.getColumnTypeName(3));
|
||||
|
@ -441,19 +456,19 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
|
|||
assertEquals("hello0", rs.getString("a_s"));
|
||||
assertEquals("hello0", rs.getString(3));
|
||||
|
||||
assertEquals(10D, rs.getObject("a_f"));
|
||||
assertEquals(10D, rs.getObject("my_float_col"));
|
||||
assertEquals(10D, rs.getObject(4));
|
||||
assertEquals(10D, rs.getDouble("a_f"), 0);
|
||||
assertEquals(10D, rs.getDouble("my_float_col"), 0);
|
||||
assertEquals(10D, rs.getDouble(4), 0);
|
||||
assertEquals(10F, rs.getFloat("a_f"), 0);
|
||||
assertEquals(10F, rs.getFloat("my_float_col"), 0);
|
||||
assertEquals(10F, rs.getFloat(4), 0);
|
||||
assertEquals(10, rs.getInt("a_f"), 0);
|
||||
assertEquals(10, rs.getInt("my_float_col"), 0);
|
||||
assertEquals(10, rs.getInt(4), 0);
|
||||
assertEquals(10L, rs.getLong("a_f"), 0);
|
||||
assertEquals(10L, rs.getLong("my_float_col"), 0);
|
||||
assertEquals(10L, rs.getLong(4), 0);
|
||||
assertEquals(10, rs.getShort("a_f"), 0);
|
||||
assertEquals(10, rs.getShort("my_float_col"), 0);
|
||||
assertEquals(10, rs.getShort(4), 0);
|
||||
assertEquals(10, rs.getByte("a_f"), 0);
|
||||
assertEquals(10, rs.getByte("my_float_col"), 0);
|
||||
assertEquals(10, rs.getByte(4), 0);
|
||||
|
||||
assertTrue(rs.next());
|
||||
|
@ -476,19 +491,19 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
|
|||
assertEquals("hello3", rs.getString("a_s"));
|
||||
assertEquals("hello3", rs.getString(3));
|
||||
|
||||
assertEquals(9D, rs.getObject("a_f"));
|
||||
assertEquals(9D, rs.getObject("my_float_col"));
|
||||
assertEquals(9D, rs.getObject(4));
|
||||
assertEquals(9D, rs.getDouble("a_f"), 0);
|
||||
assertEquals(9D, rs.getDouble("my_float_col"), 0);
|
||||
assertEquals(9D, rs.getDouble(4), 0);
|
||||
assertEquals(9F, rs.getFloat("a_f"), 0);
|
||||
assertEquals(9F, rs.getFloat("my_float_col"), 0);
|
||||
assertEquals(9F, rs.getFloat(4), 0);
|
||||
assertEquals(9, rs.getInt("a_f"), 0);
|
||||
assertEquals(9, rs.getInt("my_float_col"), 0);
|
||||
assertEquals(9, rs.getInt(4), 0);
|
||||
assertEquals(9L, rs.getLong("a_f"), 0);
|
||||
assertEquals(9L, rs.getLong("my_float_col"), 0);
|
||||
assertEquals(9L, rs.getLong(4), 0);
|
||||
assertEquals(9, rs.getShort("a_f"), 0);
|
||||
assertEquals(9, rs.getShort("my_float_col"), 0);
|
||||
assertEquals(9, rs.getShort(4), 0);
|
||||
assertEquals(9, rs.getByte("a_f"), 0);
|
||||
assertEquals(9, rs.getByte("my_float_col"), 0);
|
||||
assertEquals(9, rs.getByte(4), 0);
|
||||
|
||||
assertFalse(rs.next());
|
||||
|
|
Loading…
Reference in New Issue