You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "phartnett (via GitHub)" <gi...@apache.org> on 2024/02/22 00:13:45 UTC
[PR] Csharp setnull [arrow]
phartnett opened a new pull request, #40189:
URL: https://github.com/apache/arrow/pull/40189
<!--
Thanks for opening a pull request!
If this is your first pull request you can find detailed information on how
to contribute here:
* [New Contributor's Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
* [Contributing Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
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}
-->
### Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
### What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
### Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
### Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please uncomment the line below and explain which changes are breaking.
-->
<!-- **This PR includes breaking changes to public APIs.** -->
<!--
Please uncomment the line below (and provide explanation) if the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld). We use this to highlight fixes to issues that may affect users without their knowledge. For this reason, fixing bugs that cause errors don't count, since those are usually obvious.
-->
<!-- **This PR contains a "Critical Fix".** -->
--
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
Re: [PR] GH-#40188 :C# Csharp setnull [arrow]
Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher commented on code in PR #40189:
URL: https://github.com/apache/arrow/pull/40189#discussion_r1536656191
##########
csharp/src/Apache.Arrow/Arrays/BinaryArray.cs:
##########
@@ -253,14 +253,25 @@ public TBuilder Resize(int length)
public TBuilder Swap(int i, int j)
Review Comment:
I think most users would expect this to swap the ith and jth elements of the binary array and not the ith and jth bytes of the underlying buffer -- or, at least I would. That is, if my logical array were to look like `{null, {0x00, 0x01, 0x02}, {0xff}, {0xfe, 0xfd}}` then calling Swap(1, 2) should result in `{null, {0xff}, {0x00, 0x01, 0x02}, {0xfe, 0xfd}}`. But with this change, calling Swap(1, 2) would instead produce `{null, {0xff}, {0x01, 0x00, 0x02}, {0xfe, 0xfd}}`.
##########
csharp/src/Apache.Arrow/Arrays/BinaryArray.cs:
##########
@@ -253,14 +253,25 @@ public TBuilder Resize(int length)
public TBuilder Swap(int i, int j)
{
- // TODO: Implement
- throw new NotImplementedException();
+ byte ti = ValueBuffer.Span[i];
+ byte tj = ValueBuffer.Span[j];
+ ValueBuffer.Span[i] = tj;
+ ValueBuffer.Span[j] = ti;
+ return Instance;
}
public TBuilder Set(int index, byte value)
{
- // TODO: Implement
- throw new NotImplementedException();
+ ValueBuffer.Span[index] = value;
+ ValidityBuffer.Set(index);
+ return Instance;
+ }
+
+ public TBuilder SetNull(int index)
+ {
+ ValueBuffer.Span[index] = default;
+ ValidityBuffer.Set(index, false);
Review Comment:
The indexes in the validity buffer don't align with the indexes in the value buffer unless each element of the binary array has a length of exactly one.
To implement SetNull correctly, if the previous value was non-null then it would be necessary to compact the value buffer and adjust all of the offsets in ValueOffsets.
##########
csharp/src/Apache.Arrow/Arrays/BinaryArray.cs:
##########
@@ -253,14 +253,25 @@ public TBuilder Resize(int length)
public TBuilder Swap(int i, int j)
{
- // TODO: Implement
- throw new NotImplementedException();
+ byte ti = ValueBuffer.Span[i];
+ byte tj = ValueBuffer.Span[j];
+ ValueBuffer.Span[i] = tj;
+ ValueBuffer.Span[j] = ti;
+ return Instance;
}
public TBuilder Set(int index, byte value)
{
- // TODO: Implement
- throw new NotImplementedException();
+ ValueBuffer.Span[index] = value;
+ ValidityBuffer.Set(index);
+ return Instance;
+ }
+
+ public TBuilder SetNull(int index)
+ {
+ ValueBuffer.Span[index] = default;
+ ValidityBuffer.Set(index, false);
Review Comment:
(The same comment roughly applies to the implementation of Set, above.)
--
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
Re: [PR] GH-#40188 :C# Csharp setnull [arrow]
Posted by "phartnett (via GitHub)" <gi...@apache.org>.
phartnett commented on PR #40189:
URL: https://github.com/apache/arrow/pull/40189#issuecomment-3548811899
Thanks Curt!
Looks like you got around to working on it... it fell down my priority list
--
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
Re: [PR] GH-#40188 :C# Csharp setnull [arrow]
Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher commented on code in PR #40189:
URL: https://github.com/apache/arrow/pull/40189#discussion_r1537723184
##########
csharp/src/Apache.Arrow/Arrays/BinaryArray.cs:
##########
@@ -253,14 +255,99 @@ public TBuilder Resize(int length)
public TBuilder Swap(int i, int j)
{
- // TODO: Implement
- throw new NotImplementedException();
+ // Retrieve byte arrays for elements i and j
+ var iBytes = GetValueBytes(i);
+ var jBytes = GetValueBytes(j);
+
+ Set(i, jBytes);
+ Set(j, iBytes);
+
+ ValidityBuffer.Swap(i, j);
+ return Instance;
}
+
public TBuilder Set(int index, byte value)
{
- // TODO: Implement
- throw new NotImplementedException();
+ int currentStart = ValueOffsets.Span[index];
+ int currentEnd = ValueOffsets.Span[index + 1];
+ int newEnd = currentStart + 1;
+
+ int currentLength = currentEnd - currentStart;
+ int newSize = 1;
+ int diffSize = currentLength - newSize;
+ if (currentLength != 1)
+ {
+ ValueBuffer.Span.Slice(currentStart, currentLength).Clear();
+ ValueBuffer.Span[currentStart] = value;
+ ValueBuffer.Span.Slice(currentEnd, Length - currentEnd)
+ .CopyTo(ValueBuffer.Span.Slice(newEnd, Length - newEnd));
+ ValueBuffer.Span.Slice(Length - diffSize, diffSize).Clear();
+ AdjustOffsets(index, currentLength - 1);
+ }
+
+ ValueBuffer.Span[index] = value;
+ ValidityBuffer.Set(index);
+ return Instance;
+ }
+
+ public TBuilder Set(int index, ReadOnlySpan<byte> bytes)
+ {
+ int startOffset = ValueOffsets.Span[index];
+ int newLength = bytes.Length;
+ bool isNull = bytes.IsEmpty;
Review Comment:
I don't think this code uses an empty span to mean null; an empty span is just a value of length zero.
##########
csharp/src/Apache.Arrow/Arrays/BinaryArray.cs:
##########
@@ -19,6 +19,8 @@
using System.Runtime.CompilerServices;
using Apache.Arrow.Memory;
using System.Collections;
+using System.ComponentModel.Design;
+using System.Threading.Tasks.Sources;
Review Comment:
I suspect that these aren't needed. If you're using VS2022, it's extremely trigger-happy about adding "using" statements.
--
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
Re: [PR] Csharp setnull [arrow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #40189:
URL: https://github.com/apache/arrow/pull/40189#issuecomment-1958431364
<!--
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 - Contributing Overview](https://arrow.apache.org/docs/developers/overview.html)
--
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
Re: [PR] GH-#40188 :C# Csharp setnull [arrow]
Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher commented on PR #40189:
URL: https://github.com/apache/arrow/pull/40189#issuecomment-3548800156
@phartnett, I'm going to close this PR as it's been stale for ~18 months and we've moved to a new repository. Please feel free to resubmit an updated version of it there.
--
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
Re: [PR] GH-#40188 :C# Csharp setnull [arrow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #40189:
URL: https://github.com/apache/arrow/pull/40189#issuecomment-3547061168
Thank you for your contribution. Unfortunately, this pull request has been marked as stale because it has had no activity in the past 365 days. Please remove the stale label or comment below, or this PR will be closed in 14 days. Feel free to re-open this if it has been closed in error. If you do not have repository permissions to reopen the PR, please tag a maintainer.
--
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
Re: [PR] GH-#40188 :C# Csharp setnull [arrow]
Posted by "phartnett (via GitHub)" <gi...@apache.org>.
phartnett commented on PR #40189:
URL: https://github.com/apache/arrow/pull/40189#issuecomment-2020589500
@CurtHagenlocher I locally added some unit tests... and I have some work to do.
I'll let you know when I've got something passing tests!
--
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
Re: [PR] GH-#40188 :C# Csharp setnull [arrow]
Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher closed pull request #40189: GH-#40188 :C# Csharp setnull
URL: https://github.com/apache/arrow/pull/40189
--
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