Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions csharp/Apache.Arrow.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29926.136
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apache.Arrow", "src\Apache.Arrow\Apache.Arrow.csproj", "{BA6B2B0D-EAAE-4183-8A39-1B9CF571F71F}"
EndProject
Expand All @@ -23,9 +23,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apache.Arrow.Compression",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apache.Arrow.Compression.Tests", "test\Apache.Arrow.Compression.Tests\Apache.Arrow.Compression.Tests.csproj", "{5D7FF380-B7DF-4752-B415-7C08C70C9F06}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Arrow.Flight.Sql.Tests", "test\Apache.Arrow.Flight.Sql.Tests\Apache.Arrow.Flight.Sql.Tests.csproj", "{DCC99EB1-4E60-4F0D-AEA9-C44A4C0C8B1D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apache.Arrow.Flight.Sql.Tests", "test\Apache.Arrow.Flight.Sql.Tests\Apache.Arrow.Flight.Sql.Tests.csproj", "{DCC99EB1-4E60-4F0D-AEA9-C44A4C0C8B1D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Arrow.Flight.Sql", "src\Apache.Arrow.Flight.Sql\Apache.Arrow.Flight.Sql.csproj", "{2ADE087A-B424-4895-8CC5-10170D10BA62}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apache.Arrow.Flight.Sql", "src\Apache.Arrow.Flight.Sql\Apache.Arrow.Flight.Sql.csproj", "{2ADE087A-B424-4895-8CC5-10170D10BA62}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apache.Arrow.Acero", "src\Apache.Arrow.Acero\Apache.Arrow.Acero.csproj", "{E4D30783-5506-4E62-8491-4191A249B335}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apache.Arrow.Acero.Tests", "test\Apache.Arrow.Acero.Tests\Apache.Arrow.Acero.Tests.csproj", "{A5D6A064-9AC2-4C60-9BF5-E6C834A90232}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -81,6 +85,14 @@ Global
{2ADE087A-B424-4895-8CC5-10170D10BA62}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2ADE087A-B424-4895-8CC5-10170D10BA62}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2ADE087A-B424-4895-8CC5-10170D10BA62}.Release|Any CPU.Build.0 = Release|Any CPU
{E4D30783-5506-4E62-8491-4191A249B335}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4D30783-5506-4E62-8491-4191A249B335}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4D30783-5506-4E62-8491-4191A249B335}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4D30783-5506-4E62-8491-4191A249B335}.Release|Any CPU.Build.0 = Release|Any CPU
{A5D6A064-9AC2-4C60-9BF5-E6C834A90232}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5D6A064-9AC2-4C60-9BF5-E6C834A90232}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5D6A064-9AC2-4C60-9BF5-E6C834A90232}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5D6A064-9AC2-4C60-9BF5-E6C834A90232}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
16 changes: 16 additions & 0 deletions csharp/src/Apache.Arrow.Acero/Apache.Arrow.Acero.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GLibSharp" Version="3.24.24.95" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Apache.Arrow\Apache.Arrow.csproj" />
</ItemGroup>

</Project>
46 changes: 46 additions & 0 deletions csharp/src/Apache.Arrow.Acero/AsyncRecordBatchStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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.

using Apache.Arrow.Ipc;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Apache.Arrow.Acero
{
public class AsyncRecordBatchStream : IArrowArrayStream
{
private readonly IAsyncEnumerator<RecordBatch> _recordBatchEnumerator;
private readonly Schema _schema;

public Schema Schema => _schema;

public AsyncRecordBatchStream(IAsyncEnumerable<RecordBatch> _recordBatches, Schema schema)
{
_recordBatchEnumerator = _recordBatches.GetAsyncEnumerator();
_schema = schema;
}

public async ValueTask<RecordBatch> ReadNextRecordBatchAsync(CancellationToken cancellationToken = default)
{
await _recordBatchEnumerator.MoveNextAsync();
return _recordBatchEnumerator.Current;
}

public void Dispose()
{
}
}
}
72 changes: 72 additions & 0 deletions csharp/src/Apache.Arrow.Acero/CLib.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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.

using System;
using System.Runtime.InteropServices;

namespace Apache.Arrow.Acero
{
namespace CLib
{
public struct GError { }
public struct GArrowExecutePlan { }
public struct GArrowSourceNodeOptions { }
public struct GArrowRecordBatch { }
public struct GArrowSchema { }
public struct GArrowField { }
public struct GArrowExecuteNode { }
public struct GArrowHashJoinNodeOptions { }
public struct GArrowSinkNodeOptions { }
public struct GArrowRecordBatchReader { }
[StructLayout(LayoutKind.Sequential)]
public struct GArrowExecuteNodeOptions
{
IntPtr debug_opts;
}
public struct GArrowFilterNodeOptions { }
public struct GArrowExpression { }
public struct GArrowCallExpression { }
public struct GArrowFunctionOptions { }
public struct GArrowFieldExpression { }
public struct GArrowDatum { }
public struct GArrowScalarDatum { }
public struct GArrowBuffer { }
public struct GArrowStringScalar { }
public struct GArrowInt8Scalar { }
public struct GArrowSortOptions { }
public struct GArrowSortKey { }
public struct GArrowProjectNodeOptions { }
public struct GArrowInt32Scalar { }
public struct GList {}

public enum GArrowJoinType
{
GARROW_JOIN_TYPE_LEFT_SEMI,
GARROW_JOIN_TYPE_RIGHT_SEMI,
GARROW_JOIN_TYPE_LEFT_ANTI,
GARROW_JOIN_TYPE_RIGHT_ANTI,
GARROW_JOIN_TYPE_INNER,
GARROW_JOIN_TYPE_LEFT_OUTER,
GARROW_JOIN_TYPE_RIGHT_OUTER,
GARROW_JOIN_TYPE_FULL_OUTER
}

public enum GArrowSortOrder
{
GARROW_SORT_ORDER_ASCENDING,
GARROW_SORT_ORDER_DESCENDING
}
}
}
108 changes: 108 additions & 0 deletions csharp/src/Apache.Arrow.Acero/Declaration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// 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.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Apache.Arrow.Ipc;

namespace Apache.Arrow.Acero
{
public class Declaration
{
private readonly string _factoryName;
private readonly ExecNodeOptions _options;
private readonly ExecNodeFactoryRegistry _registry;

public List<Declaration> Inputs { get; set; } = new();

public Declaration(string factoryName, ExecNodeOptions options = null, List<Declaration> inputs = null, ExecNodeFactoryRegistry registry = null)
{
_factoryName = factoryName;
_options = options;
_registry = registry ?? new DefaultExecNodeFactoryRegistry();

if (inputs != null) Inputs = inputs;
}

public static Declaration FromSequence(List<Declaration> decls)
{
var items = decls.ToList();

Declaration first = items.Last();
items.RemoveAt(items.Count - 1);

Declaration receiver = first;

while (items.Any())
{
Declaration input = items.Last();
items.RemoveAt(items.Count - 1);

receiver.Inputs.Add(input);
receiver = receiver.Inputs.First();
}

return first;
}

public Task<IArrowArrayStream> ToRecordBatchReader(Schema schema)
{
return ToRecordBatchReader(this, schema);
}

public static async Task<IArrowArrayStream> ToRecordBatchReader(Declaration declaration, Schema schema)
{
var sinkNodeOptions = new SinkNodeOptions(schema);
var plan = new ExecPlan();

Declaration sinkNode = FromSequence(
new List<Declaration>
{
declaration,
new Declaration("sink", sinkNodeOptions)
});

sinkNode.AddToPlan(plan);

if (!plan.Validate())
throw new InvalidOperationException("Plan is not valid");

await plan.Init();

plan.StartProducing();

return sinkNodeOptions.GetRecordBatchReader();
}

private ExecNode AddToPlan(ExecPlan plan)
{
var inputNodes = new List<ExecNode>();

foreach (Declaration input in Inputs)
{
ExecNode inputNode = input.AddToPlan(plan);
inputNodes.Add(inputNode);
}

ExecNode node = _registry.MakeNode(_factoryName, plan, _options, inputNodes);

plan.AddNode(node);

return node;
}
}
}
58 changes: 58 additions & 0 deletions csharp/src/Apache.Arrow.Acero/DefaultExecNodeFactoryRegistry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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.

using System;
using System.Collections.Generic;

namespace Apache.Arrow.Acero
{
public abstract class ExecNodeFactoryRegistry
{
public abstract ExecNode MakeNode(string factoryName, ExecPlan plan, ExecNodeOptions options, List<ExecNode> inputs);
}

public class DefaultExecNodeFactoryRegistry : ExecNodeFactoryRegistry
{
public override ExecNode MakeNode(string factoryName, ExecPlan plan, ExecNodeOptions options, List<ExecNode> inputs)
{
switch (factoryName)
{
case "sink":
return new SinkNode(options as SinkNodeOptions, plan, inputs);

case "record_batch_source":
return new RecordBatchSourceNode(options as RecordBatchSourceNodeOptions, plan);

case "record_batch_reader_source":
return new RecordBatchReaderSourceNode(options as RecordBatchReaderSourceNodeOptions, plan);

case "hashjoin":
return new HashJoinNode(options as HashJoinNodeOptions, plan, inputs);

case "filter":
return new FilterNode(options as FilterNodeOptions, plan, inputs);

case "union":
return new UnionNode(plan, inputs);

case "project":
return new ProjectNode(options as ProjectNodeOptions, plan, inputs);

default:
throw new InvalidOperationException($"Unknown factory {factoryName}");
}
}
}
}
29 changes: 29 additions & 0 deletions csharp/src/Apache.Arrow.Acero/ExceptionUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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.

using System;
using Apache.Arrow.Acero.CLib;

namespace Apache.Arrow.Acero
{
public static class ExceptionUtil
{
public static unsafe void ThrowOnError(GError** error)
{
if ((IntPtr)error != IntPtr.Zero)
throw new GLib.GException((IntPtr)error);
}
}
}
Loading