Skip to content

Commit

Permalink
Implemented getters for various datatypes
Browse files Browse the repository at this point in the history
  • Loading branch information
prash-mi committed Sep 17, 2021
1 parent 03762bf commit 9e567fe
Showing 1 changed file with 64 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package com.google.cloud.bigquery;

import com.google.api.services.bigquery.model.TableRow;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.sql.*;
import java.util.Map;
Expand All @@ -31,7 +29,7 @@ public class BigQueryResultSetImpl<T> extends AbstractJdbcResultSet
private final Schema schema;
private final long totalRows;
// private final ResultSet nextRow;
private final Map<String, String> nameType;
private final Map<String, String> nameType; // TODO: Remove
private final BlockingQueue<T> buffer; // TableRow
private T cursor;

Expand Down Expand Up @@ -79,197 +77,98 @@ public Object getObject(String fieldName) throws SQLException {
if (cursor instanceof TableRow) {
TableRow currentRow = (TableRow) cursor;
if (currentRow == null) {
throw new SQLException("No rows left"); // TODO rephrase exception message
throw new SQLException("No rows left");
}
return currentRow.get(fieldName);
}
// TODO: Add similar clauses for Apache Arrow and Avro
// TODO: Add similar clauses for Apache Arrow
return null;
}

@Override
public String getString(String fieldName) throws SQLException {
Object value = getObject(fieldName);
if (value == null || !(value instanceof String)) {
return null;
if (value == null) {
throw new SQLException("fieldName can't be null");
} else if (!(value instanceof String)) {
throw new SQLException("value not in instance of String");
} else {
return (String) value;
}
}

/** ****TODO Methods - to be impemented****** */
@Override
public long getLong(String columnLabel) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public float getFloat(String columnLabel) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public double getDouble(String columnLabel) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public void close() throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public boolean wasNull() throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public String getString(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public boolean getBoolean(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public byte getByte(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public short getShort(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public int getInt(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public long getLong(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public float getFloat(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public double getDouble(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public byte[] getBytes(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public Date getDate(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public Time getTime(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public Timestamp getTimestamp(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public InputStream getAsciiStream(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public InputStream getUnicodeStream(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

@Override
public InputStream getBinaryStream(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
public long getLong(String fieldName) throws SQLException {
Object value = getObject(fieldName);
if (value == null) {
throw new SQLException("fieldName can't be null");
} else if (!(value instanceof Long)) {
throw new SQLException("value not in instance of Long");
} else {
return Long.parseLong(String.valueOf(value));
}
}

@Override
public int findColumn(String columnLabel) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
public double getDouble(String fieldName) throws SQLException {
Object value = getObject(fieldName);
if (value == null) {
throw new SQLException("fieldName can't be null");
} else if (!(value instanceof Double)) {
throw new SQLException("value not in instance of Double");
} else {
return Double.parseDouble(String.valueOf(value));
}
}

@Override
public Reader getCharacterStream(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
public BigDecimal getBigDecimal(String fieldName) throws SQLException {
Object value = getObject(fieldName);
if (value == null) {
throw new SQLException("fieldName can't be null");
} else if (!(value instanceof Long
|| value instanceof Double
|| value instanceof BigDecimal
|| value instanceof String)) {
throw new SQLException("value cannot be converted to BigDecimal");
} else {
return new BigDecimal(String.valueOf(value));
}
}

@Override
public Reader getCharacterStream(String columnLabel) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
public boolean getBoolean(String fieldName) throws SQLException {
Object value = getObject(fieldName);
if (value == null) {
throw new SQLException("fieldName can't be null");
} else if (!(value instanceof Boolean || (value instanceof String))) {
throw new SQLException("value not in instance of Boolean");
} else {
return Boolean.parseBoolean(String.valueOf(value));
}
}

@Override
public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
public byte getByte(String fieldName) throws SQLException {
Object value = getObject(fieldName);
if (value == null) {
throw new SQLException("fieldName can't be null");
} else if (!(value instanceof Byte || (value instanceof String))) {
throw new SQLException("value not in instance of Boolean");
} else {
return Byte.parseByte(String.valueOf(value));
}
}

@Override
public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
// TODO: Implement the logic
throw new RuntimeException("Not implemented");
}

/*
TODO: Create methods to meet the following signature?
while(resultSet.next()) {
resultSet.getString ("name");
resultSet.getInt ("age");
resultSet.getBigDecimal("coefficient");
// etc.
public Timestamp getTimestamp(String fieldName) throws SQLException {
Object value = getObject(fieldName);
if (value == null) {
throw new SQLException("fieldName can't be null");
} else if (!(value instanceof Long || value instanceof Timestamp || value instanceof String)) {
throw new SQLException("value cannot be converted to Timestamp");
} else {
return Timestamp.valueOf(String.valueOf(value));
}
}
*/

}

0 comments on commit 9e567fe

Please sign in to comment.