-
Notifications
You must be signed in to change notification settings - Fork 94
GH-853: Allow ISO String Binding for Date, Time, and Timestamp #852
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
Open
sanskritimbora
wants to merge
3
commits into
apache:main
Choose a base branch
from
sanskritimbora:Allow-ISO-String-Binding-for-Date-Time-TimeStamp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...t/java/org/apache/arrow/driver/jdbc/converter/impl/DateAvaticaParameterConverterTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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. | ||
| */ | ||
| package org.apache.arrow.driver.jdbc.converter.impl; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import java.time.LocalDate; | ||
| import org.apache.arrow.memory.RootAllocator; | ||
| import org.apache.arrow.vector.DateDayVector; | ||
| import org.apache.arrow.vector.DateMilliVector; | ||
| import org.apache.arrow.vector.IntVector; | ||
| import org.apache.arrow.vector.types.DateUnit; | ||
| import org.apache.arrow.vector.types.pojo.ArrowType; | ||
| import org.apache.calcite.avatica.ColumnMetaData; | ||
| import org.apache.calcite.avatica.remote.TypedValue; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class DateAvaticaParameterConverterTest { | ||
| private RootAllocator allocator; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| allocator = new RootAllocator(Long.MAX_VALUE); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void tearDown() { | ||
| allocator.close(); | ||
| } | ||
|
|
||
| @Test | ||
| void testBindParameterWithStringDateMilliVector() { | ||
| try (DateMilliVector vector = new DateMilliVector("date", allocator)) { | ||
| DateAvaticaParameterConverter converter = | ||
| new DateAvaticaParameterConverter(new ArrowType.Date(DateUnit.DAY)); | ||
| String dateStr = "2023-09-15"; | ||
| TypedValue typedValue = TypedValue.create(ColumnMetaData.Rep.STRING.toString(), dateStr); | ||
| boolean result = converter.bindParameter(vector, typedValue, 0); | ||
| assertTrue(result); | ||
| assertEquals( | ||
| (int) (LocalDate.parse(dateStr).toEpochDay() * 24 * 60 * 60 * 1000), vector.get(0)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void testBindParameterWithStringDateDayVector() { | ||
| try (DateDayVector vector = new DateDayVector("date", allocator)) { | ||
| DateAvaticaParameterConverter converter = | ||
| new DateAvaticaParameterConverter(new ArrowType.Date(DateUnit.DAY)); | ||
| String dateStr = "2023-09-15"; | ||
| TypedValue typedValue = TypedValue.create(ColumnMetaData.Rep.STRING.toString(), dateStr); | ||
| boolean result = converter.bindParameter(vector, typedValue, 0); | ||
| assertTrue(result); | ||
| assertEquals((int) LocalDate.parse(dateStr).toEpochDay(), vector.get(0)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void testBindParameterWithEpochDays() { | ||
| try (DateDayVector vector = new DateDayVector("date", allocator)) { | ||
| DateAvaticaParameterConverter converter = | ||
| new DateAvaticaParameterConverter(new ArrowType.Date(DateUnit.DAY)); | ||
| int days = 19500; | ||
| TypedValue typedValue = TypedValue.create(ColumnMetaData.Rep.INTEGER.toString(), days); | ||
| boolean result = converter.bindParameter(vector, typedValue, 0); | ||
| assertTrue(result); | ||
| assertEquals(days, vector.get(0)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void testBindParameterWithUnsupportedVector() { | ||
| try (IntVector vector = new IntVector("int", allocator)) { | ||
| DateAvaticaParameterConverter converter = | ||
| new DateAvaticaParameterConverter(new ArrowType.Date(DateUnit.DAY)); | ||
| TypedValue typedValue = TypedValue.create(ColumnMetaData.Rep.STRING.toString(), "2023-09-15"); | ||
| boolean result = converter.bindParameter(vector, typedValue, 0); | ||
| assertFalse(result); | ||
| } | ||
| } | ||
| } |
133 changes: 133 additions & 0 deletions
133
...t/java/org/apache/arrow/driver/jdbc/converter/impl/TimeAvaticaParameterConverterTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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. | ||
| */ | ||
| package org.apache.arrow.driver.jdbc.converter.impl; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import org.apache.arrow.memory.BufferAllocator; | ||
| import org.apache.arrow.memory.RootAllocator; | ||
| import org.apache.arrow.vector.TimeMicroVector; | ||
| import org.apache.arrow.vector.TimeMilliVector; | ||
| import org.apache.arrow.vector.TimeNanoVector; | ||
| import org.apache.arrow.vector.TimeSecVector; | ||
| import org.apache.arrow.vector.types.TimeUnit; | ||
| import org.apache.arrow.vector.types.pojo.ArrowType; | ||
| import org.apache.calcite.avatica.ColumnMetaData; | ||
| import org.apache.calcite.avatica.remote.TypedValue; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class TimeAvaticaParameterConverterTest { | ||
| private BufferAllocator allocator; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| allocator = new RootAllocator(Long.MAX_VALUE); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void tearDown() { | ||
| allocator.close(); | ||
| } | ||
|
|
||
| @Test | ||
| void testBindParameterWithIsoStringMilli() { | ||
| TimeMilliVector vector = new TimeMilliVector("t", allocator); | ||
| vector.allocateNew(1); | ||
| TimeAvaticaParameterConverter converter = | ||
| new TimeAvaticaParameterConverter(new ArrowType.Time(TimeUnit.MILLISECOND, 32)); | ||
| boolean result = | ||
| converter.bindParameter( | ||
| vector, TypedValue.create(ColumnMetaData.Rep.STRING.toString(), "21:39:50"), 0); | ||
| assertTrue(result); | ||
| assertEquals(77990000, vector.get(0)); | ||
| vector.close(); | ||
| } | ||
|
|
||
| @Test | ||
| void testBindParameterWithIsoStringMicro() { | ||
| TimeMicroVector vector = new TimeMicroVector("t", allocator); | ||
| vector.allocateNew(1); | ||
| TimeAvaticaParameterConverter converter = | ||
| new TimeAvaticaParameterConverter(new ArrowType.Time(TimeUnit.MICROSECOND, 32)); | ||
| boolean result = | ||
| converter.bindParameter( | ||
| vector, TypedValue.create(ColumnMetaData.Rep.STRING.toString(), "21:39:50.123456"), 0); | ||
| assertTrue(result); | ||
| assertEquals(77990123456L, (long) vector.get(0)); | ||
| vector.close(); | ||
| } | ||
|
|
||
| @Test | ||
| void testBindParameterWithIsoStringNano() { | ||
| TimeNanoVector vector = new TimeNanoVector("t", allocator); | ||
| vector.allocateNew(1); | ||
| TimeAvaticaParameterConverter converter = | ||
| new TimeAvaticaParameterConverter(new ArrowType.Time(TimeUnit.NANOSECOND, 64)); | ||
| boolean result = | ||
| converter.bindParameter( | ||
| vector, | ||
| TypedValue.create(ColumnMetaData.Rep.STRING.toString(), "21:39:50.123456789"), | ||
| 0); | ||
| assertTrue(result); | ||
| assertEquals(77990123456789L, (long) vector.get(0)); | ||
| vector.close(); | ||
| } | ||
|
|
||
| @Test | ||
| void testBindParameterWithIsoStringSec() { | ||
| TimeSecVector vector = new TimeSecVector("t", allocator); | ||
| vector.allocateNew(1); | ||
| TimeAvaticaParameterConverter converter = | ||
| new TimeAvaticaParameterConverter(new ArrowType.Time(TimeUnit.SECOND, 32)); | ||
| boolean result = | ||
| converter.bindParameter( | ||
| vector, TypedValue.create(ColumnMetaData.Rep.STRING.toString(), "21:39:50"), 0); | ||
| assertTrue(result); | ||
| assertEquals(77990, vector.get(0)); | ||
| vector.close(); | ||
| } | ||
|
|
||
| @Test | ||
| void testBindParameterWithIntValueMilli() { | ||
| TimeMilliVector vector = new TimeMilliVector("t", allocator); | ||
| vector.allocateNew(1); | ||
| TimeAvaticaParameterConverter converter = | ||
| new TimeAvaticaParameterConverter(new ArrowType.Time(TimeUnit.MILLISECOND, 32)); | ||
| boolean result = | ||
| converter.bindParameter( | ||
| vector, TypedValue.create(ColumnMetaData.Rep.INTEGER.toString(), 123456), 0); | ||
| assertTrue(result); | ||
| assertEquals(123456, vector.get(0)); | ||
| vector.close(); | ||
| } | ||
|
|
||
| @Test | ||
| void testBindParameterWithIntValueSec() { | ||
| TimeSecVector vector = new TimeSecVector("t", allocator); | ||
| vector.allocateNew(1); | ||
| TimeAvaticaParameterConverter converter = | ||
| new TimeAvaticaParameterConverter(new ArrowType.Time(TimeUnit.SECOND, 32)); | ||
| boolean result = | ||
| converter.bindParameter( | ||
| vector, TypedValue.create(ColumnMetaData.Rep.INTEGER.toString(), 42), 0); | ||
| assertTrue(result); | ||
| assertEquals(42, vector.get(0)); | ||
| vector.close(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, so we only allow timestamps with the
Zsuffix - but we can bind to naive timestamp vectors too. And we don't allow timestamps without the suffix. (We could always relax that later, though.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct. Currently, we only accept timestamps with the Z suffix, but we can easily relax this restriction later to support naive timestamps if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we shouldn't allow binding timestamps with timezones to columns that don't have timezones in principle. Although what happens the Z suffix is probably unambiguous in this case I think if we ever allow other timezones then it becomes a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jbonofre or @aiguofer any opinions on the behavior here?