You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "xxlaykxx (via GitHub)" <gi...@apache.org> on 2023/06/28 10:44:28 UTC
[GitHub] [arrow] xxlaykxx opened a new pull request, #36351: Added creating MapWriter in ComplexWriter.
xxlaykxx opened a new pull request, #36351:
URL: https://github.com/apache/arrow/pull/36351
Added new method rootAsMap() to ComplexWriter and implement it in ComplexWriterImpl for supporting @map type.
Previously in dremio side:
When i trying to return map like @output ComplexWrite
with this code:
org.apache.arrow.vector.complex.writer.BaseWriter.MapWriter mapWriter = out.rootAsList().map(false);
mapWriter.startMap();
for (java.util.Map.Entry<java.lang.Integer, java.lang.Integer> element : map.entrySet()) {
mapWriter.startEntry();
mapWriter.key().integer().writeInt((Integer) element.getKey());
mapWriter.value().integer().writeInt((Integer) element.getValue());
mapWriter.endEntry();
}
mapWriter.endMap();
It use UnionMapWriter and generate schema like:
EXPR$0: Map(false)<$data$: Union(Sparse, [1, 39])<struct: Struct<key: Int(32, true) not null, value: Int(32, true) not null> not null, map: Map(false)<entries: Struct<key: Int(32, true) not null, value: Int(32, true)> not null>>>
But in OutputDerivation impl class where i should create output Complete type
List<Field> children = Arrays.asList( CompleteType.INT.toField("key", false), CompleteType.INT.toField("value", false));
return new CompleteType(CompleteType.MAP.getType(), CompleteType.struct(children).toField(MapVector.DATA_VECTOR_NAME, false));
(This is only one valid case, because MapVector.initializeChildrenFromFields())
return
EXPR$0::map<key::int32, value::int32> I found a place where it start using union - PromotableWriter.promoteToUnion.
And in the end i have
SCHEMA_CHANGE ERROR: Schema changed during projection. Schema was
schema(EXPR$0::map<key::int32, value::int32>)
but then changed to
schema(EXPR$0::map<struct::struct<key::int32, value::int32>, map::map<key::int32, value::int32>>)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] github-actions[bot] commented on pull request #36351: GH-36375: [Java] Added creating MapWriter in ComplexWriter.
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #36351:
URL: https://github.com/apache/arrow/pull/36351#issuecomment-1612788267
:warning: GitHub issue #36375 **has been automatically assigned in GitHub** to PR creator.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] lidavidm commented on a diff in pull request #36351: GH-36375: [Java] Added creating MapWriter in ComplexWriter.
Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on code in PR #36351:
URL: https://github.com/apache/arrow/pull/36351#discussion_r1252035593
##########
java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java:
##########
Review Comment:
These tests don't actually seem to test ComplexWriterImpl?
##########
java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java:
##########
@@ -1563,4 +1564,108 @@ public void testStructOfList() {
Assert.assertEquals(0, size);
}
}
+
+ @Test
+ public void testMap() {
+ try (MapVector mapVector = MapVector.empty("map", allocator, false)) {
+ mapVector.allocateNew();
+ UnionMapWriter mapWriter = new UnionMapWriter(mapVector);
+ for (int i = 0; i < COUNT; i++) {
+ mapWriter.startMap();
+ for (int j = 0; j < i % 7; j++) {
+ mapWriter.startEntry();
+ if (j % 2 == 0) {
+ mapWriter.key().integer().writeInt(j);
+ mapWriter.value().integer().writeInt(j + 1);
+ } else {
+ IntHolder keyHolder = new IntHolder();
+ keyHolder.value = j;
+ IntHolder valueHolder = new IntHolder();
+ valueHolder.value = j + 1;
+ mapWriter.key().integer().write(keyHolder);
+ mapWriter.value().integer().write(valueHolder);
+ }
+ mapWriter.endEntry();
+ }
+ mapWriter.endMap();
+ }
+ mapWriter.setValueCount(COUNT);
+ UnionMapReader mapReader = new UnionMapReader(mapVector);
+ for (int i = 0; i < COUNT; i++) {
+ mapReader.setPosition(i);
+ for (int j = 0; j < i % 7; j++) {
+ mapReader.next();
+ assertEquals(j, mapReader.key().readInteger().intValue());
+ assertEquals(j + 1, mapReader.value().readInteger().intValue());
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testMapWithNulls() {
+ try (MapVector mapVector = MapVector.empty("map", allocator, false)) {
+ mapVector.allocateNew();
+ UnionMapWriter mapWriter = new UnionMapWriter(mapVector);
+ mapWriter.startMap();
+ mapWriter.startEntry();
+ mapWriter.key().integer().writeNull();
+ mapWriter.value().integer().writeInt(1);
+ mapWriter.endEntry();
+ mapWriter.endMap();
+ mapWriter.setValueCount(1);
+ UnionMapReader mapReader = new UnionMapReader(mapVector);
+ Assert.assertNull(mapReader.key().readInteger());
+ assertEquals(1, mapReader.value().readInteger().intValue());
+ }
+ }
+
+ @Test
+ public void testMapWithListKey() {
+ try (MapVector mapVector = MapVector.empty("map", allocator, false)) {
+ mapVector.allocateNew();
+ UnionMapWriter mapWriter = new UnionMapWriter(mapVector);
+ mapWriter.startMap();
+ mapWriter.startEntry();
+ mapWriter.key().list().startList();
+ for (int i = 0; i < 3; i++) {
+ mapWriter.key().list().integer().writeInt(i);
+ }
+ mapWriter.key().list().endList();
+ mapWriter.value().integer().writeInt(1);
+ mapWriter.endEntry();
+ mapWriter.endMap();
+ mapWriter.setValueCount(1);
+ UnionMapReader mapReader = new UnionMapReader(mapVector);
+ mapReader.key().next();
+ assertEquals(0, mapReader.key().reader().readInteger().intValue());
+ mapReader.key().next();
+ assertEquals(1, mapReader.key().reader().readInteger().intValue());
+ mapReader.key().next();
+ assertEquals(2, mapReader.key().reader().readInteger().intValue());
+ assertEquals(1, mapReader.value().readInteger().intValue());
+ }
+ }
+
+ @Test
+ public void testMapWithStruckKey() {
Review Comment:
typo: "struck" -> "struct"?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] xxlaykxx commented on a diff in pull request #36351: GH-36375: [Java] Added creating MapWriter in ComplexWriter.
Posted by "xxlaykxx (via GitHub)" <gi...@apache.org>.
xxlaykxx commented on code in PR #36351:
URL: https://github.com/apache/arrow/pull/36351#discussion_r1252176615
##########
java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java:
##########
@@ -1563,4 +1564,108 @@ public void testStructOfList() {
Assert.assertEquals(0, size);
}
}
+
+ @Test
+ public void testMap() {
+ try (MapVector mapVector = MapVector.empty("map", allocator, false)) {
+ mapVector.allocateNew();
+ UnionMapWriter mapWriter = new UnionMapWriter(mapVector);
+ for (int i = 0; i < COUNT; i++) {
+ mapWriter.startMap();
+ for (int j = 0; j < i % 7; j++) {
+ mapWriter.startEntry();
+ if (j % 2 == 0) {
+ mapWriter.key().integer().writeInt(j);
+ mapWriter.value().integer().writeInt(j + 1);
+ } else {
+ IntHolder keyHolder = new IntHolder();
+ keyHolder.value = j;
+ IntHolder valueHolder = new IntHolder();
+ valueHolder.value = j + 1;
+ mapWriter.key().integer().write(keyHolder);
+ mapWriter.value().integer().write(valueHolder);
+ }
+ mapWriter.endEntry();
+ }
+ mapWriter.endMap();
+ }
+ mapWriter.setValueCount(COUNT);
+ UnionMapReader mapReader = new UnionMapReader(mapVector);
+ for (int i = 0; i < COUNT; i++) {
+ mapReader.setPosition(i);
+ for (int j = 0; j < i % 7; j++) {
+ mapReader.next();
+ assertEquals(j, mapReader.key().readInteger().intValue());
+ assertEquals(j + 1, mapReader.value().readInteger().intValue());
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testMapWithNulls() {
+ try (MapVector mapVector = MapVector.empty("map", allocator, false)) {
+ mapVector.allocateNew();
+ UnionMapWriter mapWriter = new UnionMapWriter(mapVector);
+ mapWriter.startMap();
+ mapWriter.startEntry();
+ mapWriter.key().integer().writeNull();
+ mapWriter.value().integer().writeInt(1);
+ mapWriter.endEntry();
+ mapWriter.endMap();
+ mapWriter.setValueCount(1);
+ UnionMapReader mapReader = new UnionMapReader(mapVector);
+ Assert.assertNull(mapReader.key().readInteger());
+ assertEquals(1, mapReader.value().readInteger().intValue());
+ }
+ }
+
+ @Test
+ public void testMapWithListKey() {
+ try (MapVector mapVector = MapVector.empty("map", allocator, false)) {
+ mapVector.allocateNew();
+ UnionMapWriter mapWriter = new UnionMapWriter(mapVector);
+ mapWriter.startMap();
+ mapWriter.startEntry();
+ mapWriter.key().list().startList();
+ for (int i = 0; i < 3; i++) {
+ mapWriter.key().list().integer().writeInt(i);
+ }
+ mapWriter.key().list().endList();
+ mapWriter.value().integer().writeInt(1);
+ mapWriter.endEntry();
+ mapWriter.endMap();
+ mapWriter.setValueCount(1);
+ UnionMapReader mapReader = new UnionMapReader(mapVector);
+ mapReader.key().next();
+ assertEquals(0, mapReader.key().reader().readInteger().intValue());
+ mapReader.key().next();
+ assertEquals(1, mapReader.key().reader().readInteger().intValue());
+ mapReader.key().next();
+ assertEquals(2, mapReader.key().reader().readInteger().intValue());
+ assertEquals(1, mapReader.value().readInteger().intValue());
+ }
+ }
+
+ @Test
+ public void testMapWithStruckKey() {
Review Comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] xxlaykxx commented on a diff in pull request #36351: GH-36375: [Java] Added creating MapWriter in ComplexWriter.
Posted by "xxlaykxx (via GitHub)" <gi...@apache.org>.
xxlaykxx commented on code in PR #36351:
URL: https://github.com/apache/arrow/pull/36351#discussion_r1246583107
##########
java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java:
##########
@@ -362,125 +355,6 @@ public void listDecimalType() {
}
}
- @Test
- public void listTimeStampMilliTZType() {
- try (ListVector listVector = ListVector.empty("list", allocator)) {
- listVector.allocateNew();
- UnionListWriter listWriter = new UnionListWriter(listVector);
- for (int i = 0; i < COUNT; i++) {
- listWriter.startList();
- for (int j = 0; j < i % 7; j++) {
- if (j % 2 == 0) {
- listWriter.writeNull();
- } else {
- TimeStampMilliTZHolder holder = new TimeStampMilliTZHolder();
- holder.timezone = "FakeTimeZone";
- holder.value = j;
- listWriter.timeStampMilliTZ().write(holder);
- }
- }
- listWriter.endList();
- }
- listWriter.setValueCount(COUNT);
- UnionListReader listReader = new UnionListReader(listVector);
- for (int i = 0; i < COUNT; i++) {
- listReader.setPosition(i);
- for (int j = 0; j < i % 7; j++) {
- listReader.next();
- if (j % 2 == 0) {
- assertFalse("index is set: " + j, listReader.reader().isSet());
- } else {
- NullableTimeStampMilliTZHolder actual = new NullableTimeStampMilliTZHolder();
- listReader.reader().read(actual);
- assertEquals(j, actual.value);
- assertEquals("FakeTimeZone", actual.timezone);
- }
- }
- }
- }
- }
-
- @Test
- public void listDurationType() {
- try (ListVector listVector = ListVector.empty("list", allocator)) {
- listVector.allocateNew();
- UnionListWriter listWriter = new UnionListWriter(listVector);
- for (int i = 0; i < COUNT; i++) {
- listWriter.startList();
- for (int j = 0; j < i % 7; j++) {
- if (j % 2 == 0) {
- listWriter.writeNull();
- } else {
- DurationHolder holder = new DurationHolder();
- holder.unit = TimeUnit.MICROSECOND;
- holder.value = j;
- listWriter.duration().write(holder);
- }
- }
- listWriter.endList();
- }
- listWriter.setValueCount(COUNT);
- UnionListReader listReader = new UnionListReader(listVector);
- for (int i = 0; i < COUNT; i++) {
- listReader.setPosition(i);
- for (int j = 0; j < i % 7; j++) {
- listReader.next();
- if (j % 2 == 0) {
- assertFalse("index is set: " + j, listReader.reader().isSet());
- } else {
- NullableDurationHolder actual = new NullableDurationHolder();
- listReader.reader().read(actual);
- assertEquals(TimeUnit.MICROSECOND, actual.unit);
- assertEquals(j, actual.value);
- }
- }
- }
- }
- }
-
- @Test
- public void listFixedSizeBinaryType() throws Exception {
Review Comment:
my mistake - reverted
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] lidavidm merged pull request #36351: GH-36375: [Java] Added creating MapWriter in ComplexWriter.
Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm merged PR #36351:
URL: https://github.com/apache/arrow/pull/36351
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] github-actions[bot] commented on pull request #36351: Added creating MapWriter in ComplexWriter.
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #36351:
URL: https://github.com/apache/arrow/pull/36351#issuecomment-1611177965
<!--
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.
-->
Thanks for opening a pull request!
If this is not a [minor PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose
Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
Then could you also rename the pull request title in the following format?
GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
or
MINOR: [${COMPONENT}] ${SUMMARY}
In the case of PARQUET issues on JIRA the title also supports:
PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
See also:
* [Other pull requests](https://github.com/apache/arrow/pulls/)
* [Contribution Guidelines - How to contribute patches](https://arrow.apache.org/docs/developers/contributing.html#how-to-contribute-patches)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] lidavidm commented on pull request #36351: Added creating MapWriter in ComplexWriter.
Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on PR #36351:
URL: https://github.com/apache/arrow/pull/36351#issuecomment-1611298781
CC @davisusanibar
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] xxlaykxx commented on a diff in pull request #36351: GH-36375: [Java] Added creating MapWriter in ComplexWriter.
Posted by "xxlaykxx (via GitHub)" <gi...@apache.org>.
xxlaykxx commented on code in PR #36351:
URL: https://github.com/apache/arrow/pull/36351#discussion_r1252176943
##########
java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java:
##########
Review Comment:
Updated tests with using ComplexWriterImpl
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on pull request #36351: [Java] Added creating MapWriter in ComplexWriter.
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on PR #36351:
URL: https://github.com/apache/arrow/pull/36351#issuecomment-1612092692
Could you open a new issue and prepend the issue ID to the PR title like `GR-XXXX: ...`?
See the auto added comment for details: https://github.com/apache/arrow/pull/36351#issuecomment-1611177965
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] lidavidm commented on a diff in pull request #36351: GH-36375: [Java] Added creating MapWriter in ComplexWriter.
Posted by "lidavidm (via GitHub)" <gi...@apache.org>.
lidavidm commented on code in PR #36351:
URL: https://github.com/apache/arrow/pull/36351#discussion_r1246541485
##########
java/vector/src/test/java/org/apache/arrow/vector/complex/writer/TestComplexWriter.java:
##########
@@ -362,125 +355,6 @@ public void listDecimalType() {
}
}
- @Test
- public void listTimeStampMilliTZType() {
- try (ListVector listVector = ListVector.empty("list", allocator)) {
- listVector.allocateNew();
- UnionListWriter listWriter = new UnionListWriter(listVector);
- for (int i = 0; i < COUNT; i++) {
- listWriter.startList();
- for (int j = 0; j < i % 7; j++) {
- if (j % 2 == 0) {
- listWriter.writeNull();
- } else {
- TimeStampMilliTZHolder holder = new TimeStampMilliTZHolder();
- holder.timezone = "FakeTimeZone";
- holder.value = j;
- listWriter.timeStampMilliTZ().write(holder);
- }
- }
- listWriter.endList();
- }
- listWriter.setValueCount(COUNT);
- UnionListReader listReader = new UnionListReader(listVector);
- for (int i = 0; i < COUNT; i++) {
- listReader.setPosition(i);
- for (int j = 0; j < i % 7; j++) {
- listReader.next();
- if (j % 2 == 0) {
- assertFalse("index is set: " + j, listReader.reader().isSet());
- } else {
- NullableTimeStampMilliTZHolder actual = new NullableTimeStampMilliTZHolder();
- listReader.reader().read(actual);
- assertEquals(j, actual.value);
- assertEquals("FakeTimeZone", actual.timezone);
- }
- }
- }
- }
- }
-
- @Test
- public void listDurationType() {
- try (ListVector listVector = ListVector.empty("list", allocator)) {
- listVector.allocateNew();
- UnionListWriter listWriter = new UnionListWriter(listVector);
- for (int i = 0; i < COUNT; i++) {
- listWriter.startList();
- for (int j = 0; j < i % 7; j++) {
- if (j % 2 == 0) {
- listWriter.writeNull();
- } else {
- DurationHolder holder = new DurationHolder();
- holder.unit = TimeUnit.MICROSECOND;
- holder.value = j;
- listWriter.duration().write(holder);
- }
- }
- listWriter.endList();
- }
- listWriter.setValueCount(COUNT);
- UnionListReader listReader = new UnionListReader(listVector);
- for (int i = 0; i < COUNT; i++) {
- listReader.setPosition(i);
- for (int j = 0; j < i % 7; j++) {
- listReader.next();
- if (j % 2 == 0) {
- assertFalse("index is set: " + j, listReader.reader().isSet());
- } else {
- NullableDurationHolder actual = new NullableDurationHolder();
- listReader.reader().read(actual);
- assertEquals(TimeUnit.MICROSECOND, actual.unit);
- assertEquals(j, actual.value);
- }
- }
- }
- }
- }
-
- @Test
- public void listFixedSizeBinaryType() throws Exception {
Review Comment:
Why are these tests removed?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org