Skip to content

Conversation

@liyafan82
Copy link
Contributor

According to SQL convertion, sql type DATE should correspond to a format of YYYY-MM-DD, without the components for hour/minute/second/millis

Therefore, JDBC type DATE should correspond to DateDayVector, with a type width of 4, instead of 8.

@github-actions
Copy link

github-actions bot commented Dec 3, 2019

Change-Id: I604a6b2db3b0816aec6bc7c117e8172507dbdddd
@liyafan82
Copy link
Contributor Author

For example, this document gives some descriptions about the DATE type in SQL:
https://www.w3schools.com/sql/sql_dates.asp

Copy link
Contributor

@walterddr walterddr left a comment

Choose a reason for hiding this comment

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

Hi @liyafan82, thanks for fixing this issue. I have a question regarding the Datetime handling, it might've related to one of the issue I am having. could you please kindly take a look at my comment on the DateConsumer class? thanks -Rong.

return new ArrowType.Utf8();
case Types.DATE:
return new ArrowType.Date(DateUnit.MILLISECOND);
return new ArrowType.Date(DateUnit.DAY);
Copy link
Contributor

Choose a reason for hiding this comment

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

should also change line 213?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch. Thank you.

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
Copy link
Contributor

@walterddr walterddr Dec 27, 2019

Choose a reason for hiding this comment

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

should probably use java.sql.Date instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point. thank you.


@Override
public void consume(ResultSet resultSet) throws SQLException {
Date date = calendar == null ? resultSet.getDate(columnIndexInResultSet) :
Copy link
Contributor

Choose a reason for hiding this comment

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

this might be legacy, but resultSet.getDate returns java.sql.Date instead of java.util.Date.
Seems like there might've been some implicit conversion where we don't want underneath?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I agree with you that java.sql.Date is better.
Here java.sql.Date is converted to java.util.Date because the latter is the super class of the former.

@liyafan82
Copy link
Contributor Author

Hi @liyafan82, thanks for fixing this issue. I have a question regarding the Datetime handling, it might've related to one of the issue I am having. could you please kindly take a look at my comment on the DateConsumer class? thanks -Rong.

@walterddr Thanks a lot for your good points. I have revised the code accordingly. Please take another look. Thank you in advance.

Copy link
Contributor

Choose a reason for hiding this comment

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

use TimeUnit.MILLISECONDS.toDays()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion. I have revised the code. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

are SQL dates guaranteed to have the same range as DateDayVector? (i.e. should you check for overflow?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion. I have added logic to check overflow.

/**
* The number of milli-seconds in a day.
*/
public static final long MILLIS_PER_DAY = TimeUnit.DAYS.toMillis(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't there a TimeUnit.MILLIS.toDays that you can use instead of doing the division?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Revised accordly. Thanks for the good suggestion.

kszucs pushed a commit that referenced this pull request Feb 7, 2020
According to SQL convertion, sql type DATE should correspond to a format of YYYY-MM-DD, without the components for hour/minute/second/millis

Therefore, JDBC type DATE should correspond to DateDayVector, with a type width of 4, instead of 8.

Closes #5944 from liyafan82/fly_1203_date and squashes the following commits:

a6de377 <liyafan82>  Remove division in time conversion
be73192 <liyafan82>  Resolve comments
eea8b79 <liyafan82>  Sql type DATE should correspond to DateDayVector

Authored-by: liyafan82 <fan_li_ya@foxmail.com>
Signed-off-by: Micah Kornfield <emkornfield@gmail.com>
pribor pushed a commit to GlobalWebIndex/arrow that referenced this pull request Oct 24, 2025
According to SQL convertion, sql type DATE should correspond to a format of YYYY-MM-DD, without the components for hour/minute/second/millis

Therefore, JDBC type DATE should correspond to DateDayVector, with a type width of 4, instead of 8.

Closes apache#5944 from liyafan82/fly_1203_date and squashes the following commits:

a6de377 <liyafan82>  Remove division in time conversion
be73192 <liyafan82>  Resolve comments
eea8b79 <liyafan82>  Sql type DATE should correspond to DateDayVector

Authored-by: liyafan82 <fan_li_ya@foxmail.com>
Signed-off-by: Micah Kornfield <emkornfield@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants