Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDBC driver implements getDate, getTimestamp and getTime with Calendar in ResultSet #5752

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.math.MathContext;
import java.nio.charset.StandardCharsets;
import java.sql.*;
import java.util.Calendar;
import java.util.List;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.vector.VectorSchemaRoot;
Expand Down Expand Up @@ -198,6 +199,32 @@ public Date getDate(String columnName) throws SQLException {
return getDate(findColumn(columnName));
}

public Date getDate(int columnIndex, Calendar cal) throws SQLException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add @Overwrite, and can we remove it from the parent abstract class?

Date value = getDate(columnIndex);
if (value == null) {
return null;
} else {
try {
return parseDate(value, cal);
} catch (IllegalArgumentException e) {
throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to date: " + e, e);
}
}
pan3793 marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public Date getDate(String columnLabel, Calendar cal) throws SQLException {
return this.getDate(findColumn(columnLabel), cal);
}

private Date parseDate(Date value, Calendar cal) {
if (cal == null) {
cal = Calendar.getInstance();
}
cal.setTime(value);
return new Date(cal.getTimeInMillis());
}

@Override
public double getDouble(int columnIndex) throws SQLException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.math.MathContext;
import java.nio.charset.StandardCharsets;
import java.sql.*;
import java.util.Calendar;
import java.util.List;
import org.apache.hive.service.rpc.thrift.TTableSchema;
import org.apache.hive.service.rpc.thrift.TTypeId;
Expand Down Expand Up @@ -182,6 +183,33 @@ public Date getDate(String columnName) throws SQLException {
return getDate(findColumn(columnName));
}

@Override
public Date getDate(int columnIndex, Calendar cal) throws SQLException {
Date value = getDate(columnIndex);
if (value == null) {
return null;
} else {
try {
return parseDate(value, cal);
} catch (IllegalArgumentException e) {
throw new KyuubiSQLException("Cannot convert column " + columnIndex + " to date: " + e, e);
}
}
pan3793 marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public Date getDate(String columnLabel, Calendar cal) throws SQLException {
return this.getDate(findColumn(columnLabel), cal);
}

private Date parseDate(Date value, Calendar cal) {
if (cal == null) {
cal = Calendar.getInstance();
}
cal.setTime(value);
return new Date(cal.getTimeInMillis());
}

@Override
public double getDouble(int columnIndex) throws SQLException {
try {
Expand Down
Loading