forked from apache/arrow-adbc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(csharp/src/Drivers): introduce drivers for Apache systems built …
…on Thrift (apache#1710) This PR introduces new drivers built on the Thrift protocol: Hive, Impala, and Spark. The main focus has been on Spark (including Databricks) for the initial set of tests. --------- Co-authored-by: David Coe <coedavid@umich.edu> Co-authored-by: vikrantpuppala <vikrant.puppala@databricks.com> Co-authored-by: Gopal Lal <gopal.lal@databricks.com> Co-authored-by: Vikrant Puppala <vikrantpuppala@gmail.com> Co-authored-by: Gopal Lal <135012033+gopalldb@users.noreply.github.com> Co-authored-by: Jade Wang <111902719+jadewang-db@users.noreply.github.com> Co-authored-by: yunbodeng-db <104732431+yunbodeng-db@users.noreply.github.com> Co-authored-by: David Li <li.davidm96@gmail.com> Co-authored-by: Bruce Irschick <bruce.irschick@improving.com>
- Loading branch information
Showing
152 changed files
with
44,808 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,7 @@ python/doc/ | |
# Egg metadata | ||
*.egg-info | ||
|
||
.vs/ | ||
.vscode | ||
.idea/ | ||
.pytest_cache/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
csharp/src/Drivers/Apache/Apache.Arrow.Adbc.Drivers.Apache.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net472;net6.0</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="ApacheThrift" Version="0.19.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Apache.Arrow.Adbc\Apache.Arrow.Adbc.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
170 changes: 170 additions & 0 deletions
170
csharp/src/Drivers/Apache/Hive2/HiveServer2Connection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
/* | ||
* 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.Threading; | ||
using System.Threading.Tasks; | ||
using Apache.Arrow.Ipc; | ||
using Apache.Hive.Service.Rpc.Thrift; | ||
using Thrift.Protocol; | ||
using Thrift.Transport; | ||
|
||
namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2 | ||
{ | ||
public abstract class HiveServer2Connection : AdbcConnection | ||
{ | ||
const string userAgent = "AdbcExperimental/0.0"; | ||
|
||
protected TOperationHandle operationHandle; | ||
protected IReadOnlyDictionary<string, string> properties; | ||
internal TTransport transport; | ||
internal TCLIService.Client client; | ||
internal TSessionHandle sessionHandle; | ||
|
||
internal HiveServer2Connection() : this(null) | ||
{ | ||
|
||
} | ||
|
||
internal HiveServer2Connection(IReadOnlyDictionary<string, string> properties) | ||
{ | ||
this.properties = properties; | ||
} | ||
|
||
public void Open() | ||
{ | ||
TProtocol protocol = CreateProtocol(); | ||
this.transport = protocol.Transport; | ||
this.client = new TCLIService.Client(protocol); | ||
|
||
var s0 = this.client.OpenSession(CreateSessionRequest()).Result; | ||
this.sessionHandle = s0.SessionHandle; | ||
} | ||
|
||
protected abstract TProtocol CreateProtocol(); | ||
protected abstract TOpenSessionReq CreateSessionRequest(); | ||
|
||
public override IArrowArrayStream GetObjects(GetObjectsDepth depth, string catalogPattern, string dbSchemaPattern, string tableNamePattern, List<string> tableTypes, string columnNamePattern) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override IArrowArrayStream GetInfo(List<int> codes) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override IArrowArrayStream GetTableTypes() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected void PollForResponse() | ||
{ | ||
TGetOperationStatusResp statusResponse = null; | ||
do | ||
{ | ||
if (statusResponse != null) { Thread.Sleep(500); } | ||
TGetOperationStatusReq request = new TGetOperationStatusReq(this.operationHandle); | ||
statusResponse = this.client.GetOperationStatus(request).Result; | ||
} while (statusResponse.OperationState == TOperationState.PENDING_STATE || statusResponse.OperationState == TOperationState.RUNNING_STATE); | ||
} | ||
|
||
|
||
public override void Dispose() | ||
{ | ||
if (this.client != null) | ||
{ | ||
TCloseSessionReq r6 = new TCloseSessionReq(this.sessionHandle); | ||
this.client.CloseSession(r6).Wait(); | ||
|
||
this.transport.Close(); | ||
this.client.Dispose(); | ||
this.transport = null; | ||
this.client = null; | ||
} | ||
} | ||
|
||
protected Schema GetSchema() | ||
{ | ||
TGetResultSetMetadataReq request = new TGetResultSetMetadataReq(this.operationHandle); | ||
TGetResultSetMetadataResp response = this.client.GetResultSetMetadata(request).Result; | ||
return SchemaParser.GetArrowSchema(response.Schema); | ||
} | ||
|
||
sealed class GetObjectsReader : IArrowArrayStream | ||
{ | ||
HiveServer2Connection connection; | ||
Schema schema; | ||
List<TSparkArrowBatch> batches; | ||
int index; | ||
IArrowReader reader; | ||
|
||
public GetObjectsReader(HiveServer2Connection connection, Schema schema) | ||
{ | ||
this.connection = connection; | ||
this.schema = schema; | ||
} | ||
|
||
public Schema Schema { get { return schema; } } | ||
|
||
public async ValueTask<RecordBatch> ReadNextRecordBatchAsync(CancellationToken cancellationToken = default) | ||
{ | ||
while (true) | ||
{ | ||
if (this.reader != null) | ||
{ | ||
RecordBatch next = await this.reader.ReadNextRecordBatchAsync(cancellationToken); | ||
if (next != null) | ||
{ | ||
return next; | ||
} | ||
this.reader = null; | ||
} | ||
|
||
if (this.batches != null && this.index < this.batches.Count) | ||
{ | ||
this.reader = new ArrowStreamReader(new ChunkStream(this.schema, this.batches[this.index++].Batch)); | ||
continue; | ||
} | ||
|
||
this.batches = null; | ||
this.index = 0; | ||
|
||
if (this.connection == null) | ||
{ | ||
return null; | ||
} | ||
|
||
TFetchResultsReq request = new TFetchResultsReq(this.connection.operationHandle, TFetchOrientation.FETCH_NEXT, 50000); | ||
TFetchResultsResp response = await this.connection.client.FetchResults(request, cancellationToken); | ||
this.batches = response.Results.ArrowBatches; | ||
|
||
if (!response.HasMoreRows) | ||
{ | ||
this.connection = null; | ||
} | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* 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; | ||
|
||
namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2 | ||
{ | ||
public class HiveServer2Exception : AdbcException | ||
{ | ||
private string _sqlState; | ||
private int _nativeError; | ||
|
||
public HiveServer2Exception() | ||
{ | ||
} | ||
|
||
public HiveServer2Exception(string message) : base(message) | ||
{ | ||
} | ||
|
||
public HiveServer2Exception(string message, AdbcStatusCode statusCode) : base(message, statusCode) | ||
{ | ||
} | ||
|
||
public HiveServer2Exception(string message, Exception innerException) : base(message, innerException) | ||
{ | ||
} | ||
|
||
public HiveServer2Exception(string message, AdbcStatusCode statusCode, Exception innerException) : base(message, statusCode, innerException) | ||
{ | ||
} | ||
|
||
public override string SqlState | ||
{ | ||
get { return _sqlState; } | ||
} | ||
|
||
public override int NativeError | ||
{ | ||
get { return _nativeError; } | ||
} | ||
|
||
internal HiveServer2Exception SetSqlState(string sqlState) | ||
{ | ||
_sqlState = sqlState; | ||
return this; | ||
} | ||
|
||
internal HiveServer2Exception SetNativeError(int nativeError) | ||
{ | ||
_nativeError = nativeError; | ||
return this; | ||
} | ||
} | ||
} |
Oops, something went wrong.