|
| 1 | +// Licensed under the Apache License, Version 2.0 (the "License") |
| 2 | +// you may not use this file except in compliance with the License. |
| 3 | +// You may obtain a copy of the License at |
| 4 | +// |
| 5 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +// |
| 7 | +// Unless required by applicable law or agreed to in writing, software |
| 8 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +// See the License for the specific language governing permissions and |
| 11 | +// limitations under the License. |
| 12 | + |
| 13 | +using FlowtideDotNet.Core.ColumnStore; |
| 14 | +using FlowtideDotNet.Core.ColumnStore.Comparers; |
| 15 | +using FlowtideDotNet.Core.ColumnStore.DataValues; |
| 16 | +using FlowtideDotNet.Substrait.FunctionExtensions; |
| 17 | +using System; |
| 18 | +using System.Collections.Generic; |
| 19 | +using System.Linq; |
| 20 | +using System.Text; |
| 21 | +using System.Threading.Tasks; |
| 22 | + |
| 23 | +namespace FlowtideDotNet.Core.Compute.Columnar.Functions |
| 24 | +{ |
| 25 | + internal static class BuiltInListFunctions |
| 26 | + { |
| 27 | + public static void AddBuiltInListFunctions(IFunctionsRegister functionsRegister) |
| 28 | + { |
| 29 | + functionsRegister.RegisterScalarMethod(FunctionsList.Uri, FunctionsList.ListSortAscendingNullLast, typeof(BuiltInListFunctions), nameof(ListSortAscendingNullLast)); |
| 30 | + } |
| 31 | + |
| 32 | + private static IDataValue ListSortAscendingNullLast<T>(T value) |
| 33 | + where T : IDataValue |
| 34 | + { |
| 35 | + if (value.Type == ArrowTypeId.List) |
| 36 | + { |
| 37 | + var list = value.AsList; |
| 38 | + IDataValue[] newList = new IDataValue[list.Count]; |
| 39 | + for (int i = 0; i < list.Count; i++) |
| 40 | + { |
| 41 | + newList[i] = list.GetAt(i); |
| 42 | + } |
| 43 | + |
| 44 | + Array.Sort(newList, SortFieldCompareCompiler.CompareAscendingNullsLastImplementation); |
| 45 | + return new ListValue(newList); |
| 46 | + } |
| 47 | + return NullValue.Instance; |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments