forked from davidhcoe/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.
Merge branch 'dev/apache-drivers' of github.com:gopalldb/arrow-adbc i…
…nto dev/apache-drivers
- Loading branch information
Showing
144 changed files
with
43,006 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"ExpandedNodes": [ | ||
"" | ||
], | ||
"SelectedNode": "\\Apache.Arrow.Adbc.sln", | ||
"PreviewInSolutionExplorer": false | ||
} |
Binary file not shown.
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,23 @@ | ||
{ | ||
"Version": 1, | ||
"WorkspaceRootPath": "C:\\Users\\gopal.lal\\source\\repos\\arrow-adbc\\", | ||
"Documents": [], | ||
"DocumentGroupContainers": [ | ||
{ | ||
"Orientation": 0, | ||
"VerticalTabListWidth": 256, | ||
"DocumentGroups": [ | ||
{ | ||
"DockedWidth": 200, | ||
"SelectedChildIndex": -1, | ||
"Children": [ | ||
{ | ||
"$type": "Bookmark", | ||
"Name": "ST:0:0:{cce594b6-0c39-4442-ba28-10c64ac7e89f}" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
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>net7.0</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="ApacheThrift" Version="0.19.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Apache.Arrow.Adbc\Apache.Arrow.Adbc.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
209 changes: 209 additions & 0 deletions
209
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,209 @@ | ||
/* | ||
* 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) | ||
{ | ||
Dictionary<string, Dictionary<string, Dictionary<string, List<string>>>> catalogMap = new Dictionary<string, Dictionary<string, Dictionary<string, List<string>>>>(); | ||
if (depth == GetObjectsDepth.All || depth >= GetObjectsDepth.Catalogs) | ||
{ | ||
TGetCatalogsReq getCatalogsReq = new TGetCatalogsReq(this.sessionHandle); | ||
} | ||
|
||
if (depth == GetObjectsDepth.All || depth >= GetObjectsDepth.DbSchemas) | ||
{ | ||
TGetSchemasReq getSchemasReq = new TGetSchemasReq(this.sessionHandle); | ||
} | ||
|
||
if (depth == GetObjectsDepth.All || depth >= GetObjectsDepth.Tables) | ||
{ | ||
TGetTablesReq getTablesReq = new TGetTablesReq(this.sessionHandle); | ||
} | ||
|
||
if (depth == GetObjectsDepth.All) | ||
{ | ||
TGetColumnsReq columnsReq = new TGetColumnsReq(this.sessionHandle); | ||
columnsReq.CatalogName = catalogPattern; | ||
columnsReq.SchemaName = dbSchemaPattern; | ||
columnsReq.TableName = tableNamePattern; | ||
|
||
if (!string.IsNullOrEmpty(columnNamePattern)) | ||
columnsReq.ColumnName = columnNamePattern; | ||
|
||
var columnsResponse = this.client.GetColumns(columnsReq).Result; | ||
if (columnsResponse.Status.StatusCode == TStatusCode.ERROR_STATUS) | ||
{ | ||
throw new Exception(columnsResponse.Status.ErrorMessage); | ||
} | ||
|
||
this.operationHandle = columnsResponse.OperationHandle; | ||
} | ||
|
||
PollForResponse(); | ||
|
||
Schema schema = GetSchema(); | ||
|
||
return new GetObjectsReader(this,schema); | ||
} | ||
|
||
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,83 @@ | ||
/* | ||
* 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.Threading; | ||
using Apache.Hive.Service.Rpc.Thrift; | ||
|
||
namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2 | ||
{ | ||
public abstract class HiveServer2Statement : AdbcStatement | ||
{ | ||
protected HiveServer2Connection connection; | ||
protected TOperationHandle operationHandle; | ||
|
||
protected HiveServer2Statement(HiveServer2Connection connection) | ||
{ | ||
this.connection = connection; | ||
} | ||
|
||
protected virtual void SetStatementProperties(TExecuteStatementReq statement) | ||
{ | ||
} | ||
|
||
protected void ExecuteStatement() | ||
{ | ||
TExecuteStatementReq executeRequest = new TExecuteStatementReq(this.connection.sessionHandle, this.SqlQuery); | ||
SetStatementProperties(executeRequest); | ||
var executeResponse = this.connection.client.ExecuteStatement(executeRequest).Result; | ||
if (executeResponse.Status.StatusCode == TStatusCode.ERROR_STATUS) | ||
{ | ||
throw new Exception(executeResponse.Status.ErrorMessage); | ||
} | ||
|
||
this.operationHandle = executeResponse.OperationHandle; | ||
} | ||
|
||
protected void PollForResponse() | ||
{ | ||
TGetOperationStatusResp statusResponse = null; | ||
do | ||
{ | ||
if (statusResponse != null) { Thread.Sleep(500); } | ||
TGetOperationStatusReq request = new TGetOperationStatusReq(this.operationHandle); | ||
statusResponse = this.connection.client.GetOperationStatus(request).Result; | ||
} while (statusResponse.OperationState == TOperationState.PENDING_STATE || statusResponse.OperationState == TOperationState.RUNNING_STATE); | ||
} | ||
|
||
protected Schema GetSchema() | ||
{ | ||
TGetResultSetMetadataReq request = new TGetResultSetMetadataReq(this.operationHandle); | ||
TGetResultSetMetadataResp response = this.connection.client.GetResultSetMetadata(request).Result; | ||
return SchemaParser.GetArrowSchema(response.Schema); | ||
} | ||
|
||
public override void Dispose() | ||
{ | ||
if (this.operationHandle != null) | ||
{ | ||
TCloseOperationReq request = new TCloseOperationReq(this.operationHandle); | ||
this.connection.client.CloseOperation(request).Wait(); | ||
this.operationHandle = null; | ||
} | ||
|
||
base.Dispose(); | ||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.