-
Notifications
You must be signed in to change notification settings - Fork 106
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/Apache): Add support for Hive ADBC Driver wit…
…h unit tests (#2540) 1. Added support for the Hive ADBC driver with HTTP transport protocol. 2. Added new unit tests for Hive ADBC driver support. --------- Co-authored-by: Aman Goyal <[email protected]> Co-authored-by: Bruce Irschick <[email protected]>
- Loading branch information
1 parent
80094ce
commit b0a7b68
Showing
44 changed files
with
1,604 additions
and
103 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,54 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2 | ||
{ | ||
internal enum HiveServer2AuthType | ||
{ | ||
Invalid = 0, | ||
None, | ||
UsernameOnly, | ||
Basic, | ||
Empty = int.MaxValue, | ||
} | ||
|
||
internal static class HiveServer2AuthTypeParser | ||
{ | ||
internal static bool TryParse(string? authType, out HiveServer2AuthType authTypeValue) | ||
{ | ||
switch (authType?.Trim().ToLowerInvariant()) | ||
{ | ||
case null: | ||
case "": | ||
authTypeValue = HiveServer2AuthType.Empty; | ||
return true; | ||
case HiveServer2AuthTypeConstants.None: | ||
authTypeValue = HiveServer2AuthType.None; | ||
return true; | ||
case HiveServer2AuthTypeConstants.UsernameOnly: | ||
authTypeValue = HiveServer2AuthType.UsernameOnly; | ||
return true; | ||
case HiveServer2AuthTypeConstants.Basic: | ||
authTypeValue = HiveServer2AuthType.Basic; | ||
return true; | ||
default: | ||
authTypeValue = HiveServer2AuthType.Invalid; | ||
return false; | ||
} | ||
} | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
csharp/src/Drivers/Apache/Hive2/HiveServer2ConnectionFactory.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,39 @@ | ||
/* | ||
* 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.Adbc.Drivers.Apache.Hive2 | ||
{ | ||
internal class HiveServer2ConnectionFactory | ||
{ | ||
public static HiveServer2Connection NewConnection(IReadOnlyDictionary<string, string> properties) | ||
{ | ||
if (!properties.TryGetValue(HiveServer2Parameters.TransportType, out string? type)) | ||
{ | ||
|
||
throw new ArgumentException($"Required property '{HiveServer2Parameters.TransportType}' is missing. Supported types: {HiveServer2TransportTypeParser.SupportedList}", nameof(properties)); | ||
} | ||
if (!HiveServer2TransportTypeParser.TryParse(type, out HiveServer2TransportType typeValue)) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(properties), $"Unsupported or unknown value '{type}' given for property '{HiveServer2Parameters.TransportType}'. Supported types: {HiveServer2TransportTypeParser.SupportedList}"); | ||
} | ||
return new HiveServer2HttpConnection(properties); | ||
} | ||
} | ||
} |
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,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 System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2 | ||
{ | ||
internal class HiveServer2Database : AdbcDatabase | ||
{ | ||
readonly IReadOnlyDictionary<string, string> properties; | ||
|
||
internal HiveServer2Database(IReadOnlyDictionary<string, string> properties) | ||
{ | ||
this.properties = properties; | ||
} | ||
|
||
public override AdbcConnection Connect(IReadOnlyDictionary<string, string>? options) | ||
{ | ||
// connection options takes precedence over database properties for the same option | ||
IReadOnlyDictionary<string, string> mergedProperties = options == null | ||
? properties | ||
: options | ||
.Concat(properties.Where(x => !options.Keys.Contains(x.Key, StringComparer.OrdinalIgnoreCase))) | ||
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); | ||
HiveServer2Connection connection = HiveServer2ConnectionFactory.NewConnection(mergedProperties); | ||
connection.OpenAsync().Wait(); | ||
return connection; | ||
} | ||
} | ||
} |
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,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.Collections.Generic; | ||
|
||
namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2 | ||
{ | ||
public class HiveServer2Driver : AdbcDriver | ||
{ | ||
public override AdbcDatabase Open(IReadOnlyDictionary<string, string> parameters) | ||
{ | ||
return new HiveServer2Database(parameters); | ||
} | ||
} | ||
} |
Oops, something went wrong.