You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by cu...@apache.org on 2023/12/04 18:53:18 UTC

(arrow) branch main updated: GH-37359: [C#] Add ToList() to Decimal128Array and Decimal256Array (#37383)

This is an automated email from the ASF dual-hosted git repository.

curth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new d357d2d8e2 GH-37359: [C#] Add ToList() to Decimal128Array and Decimal256Array (#37383)
d357d2d8e2 is described below

commit d357d2d8e2a7210a7e9c1833dfe11821f3f0d349
Author: Danyaal Khan <da...@hotmail.co.uk>
AuthorDate: Mon Dec 4 18:53:11 2023 +0000

    GH-37359: [C#] Add ToList() to Decimal128Array and Decimal256Array (#37383)
    
    Add `ToList()` methods to `Decimal128Array` and `Decimal256Array`.
    
    * Closes: #37359
    
    Authored-by: Danyaal Khan <da...@hotmail.co.uk>
    Signed-off-by: Curt Hagenlocher <cu...@hagenlocher.org>
---
 csharp/src/Apache.Arrow/Arrays/Decimal128Array.cs | 24 +++++++++++++++++++++++
 csharp/src/Apache.Arrow/Arrays/Decimal256Array.cs | 24 +++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/csharp/src/Apache.Arrow/Arrays/Decimal128Array.cs b/csharp/src/Apache.Arrow/Arrays/Decimal128Array.cs
index 01724e2acd..0e3ec56740 100644
--- a/csharp/src/Apache.Arrow/Arrays/Decimal128Array.cs
+++ b/csharp/src/Apache.Arrow/Arrays/Decimal128Array.cs
@@ -151,6 +151,30 @@ namespace Apache.Arrow
             return DecimalUtility.GetDecimal(ValueBuffer, index, Scale, ByteWidth);
         }
 
+        public IList<decimal?> ToList(bool includeNulls = false)
+        {
+            var list = new List<decimal?>(Length);
+
+            for (int i = 0; i < Length; i++)
+            {
+                decimal? value = GetValue(i);
+
+                if (value.HasValue)
+                {
+                    list.Add(value.Value);
+                }
+                else
+                {
+                    if (includeNulls)
+                    {
+                        list.Add(null);
+                    }
+                }
+            }
+
+            return list;
+        }
+
         public string GetString(int index)
         {
             if (IsNull(index))
diff --git a/csharp/src/Apache.Arrow/Arrays/Decimal256Array.cs b/csharp/src/Apache.Arrow/Arrays/Decimal256Array.cs
index f314c2d6eb..94a47f2582 100644
--- a/csharp/src/Apache.Arrow/Arrays/Decimal256Array.cs
+++ b/csharp/src/Apache.Arrow/Arrays/Decimal256Array.cs
@@ -157,6 +157,30 @@ namespace Apache.Arrow
             return DecimalUtility.GetDecimal(ValueBuffer, index, Scale, ByteWidth);
         }
 
+        public IList<decimal?> ToList(bool includeNulls = false)
+        {
+            var list = new List<decimal?>(Length);
+
+            for (int i = 0; i < Length; i++)
+            {
+                decimal? value = GetValue(i);
+
+                if (value.HasValue)
+                {
+                    list.Add(value.Value);
+                }
+                else
+                {
+                    if (includeNulls)
+                    {
+                        list.Add(null);
+                    }
+                }
+            }
+
+            return list;
+        }
+
         public string GetString(int index)
         {
             if (IsNull(index))