birschick-bq commented on code in PR #2152:
URL: https://github.com/apache/arrow-adbc/pull/2152#discussion_r1752642762


##########
csharp/src/Drivers/Apache/Hive2/HiveServer2SchemaParser.cs:
##########
@@ -0,0 +1,60 @@
+/*
+* 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 Apache.Arrow.Types;
+using Apache.Hive.Service.Rpc.Thrift;
+
+namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2
+{
+    internal class HiveServer2SchemaParser : SchemaParser

Review Comment:
   Refactor to make available to Impala, etc.



##########
csharp/src/Drivers/Apache/Spark/SparkDatabricksConnection.cs:
##########
@@ -45,7 +46,19 @@ protected override TOpenSessionReq CreateSessionRequest()
             return req;
         }
 
-        protected override void ValidateOptions() { }
+        protected override void ValidateOptions()
+        {
+            Properties.TryGetValue(SparkParameters.DataTypeConv, out string? 
dataTypeConv);
+            IReadOnlyCollection<HiveServer2DataTypeConversion> 
dataTypeConvValue = HiveServer2DataTypeConversionConstants.Parse(dataTypeConv);
+            // Note: In Databricks, scalar types are provided implicitly.
+            IReadOnlyCollection<HiveServer2DataTypeConversion> 
unsupportedConversions = dataTypeConvValue
+                .Except([HiveServer2DataTypeConversion.None, 
HiveServer2DataTypeConversion.Scalar, HiveServer2DataTypeConversion.Empty])
+                .ToList();
+            if (unsupportedConversions.Count > 0) {
+                throw new NotImplementedException($"Invalid or unsupported 
data type conversion option: '{dataTypeConv}'. Supported values: 
{HiveServer2DataTypeConversionConstants.SupportedList}");

Review Comment:
   Handle the case of an invalid conversion option.



##########
csharp/src/Drivers/Apache/Spark/README.md:
##########
@@ -35,7 +35,7 @@ but can also be passed in the call to `AdbcDatabase.Connect`.
 | `uri`                  | The full URI that includes scheme, host, port and 
path. If set, this property takes precedence over `adbc.spark.host`, 
`adbc.spark.port` and `adbc.spark.path`. | |
 | `username`             | The user name used for basic authentication | |
 | `password`             | The password for the user name used for basic 
authentication. | |
-| `adbc.spark.data_type_conv` | Comma-separated list of data conversion 
options. Each option indicates the type of conversion to perform on data 
returned from the Spark server. <br><br>Allowed values: `none`. <br><br>Option 
`none` indicates there is no conversion from Spark type to native type (i.e., 
no conversion from String to Timestamp for Apache Spark over HTTP). Example 
`adbc.spark.conv_data_type=none`. <br><br>(_Planned supported values_: 
`scalar`. Option `scalar` will perform conversion (if necessary) from the Spark 
data type to corresponding Arrow data types for types `DATE/Date32/DateTime`, 
`DECIMAL/Decimal128/SqlDecimal`, and `TIMESTAMP/Timestamp/DateTimeOffset`. 
Example `adbc.spark.conv_data_type=scalar`) | `scalar` |
+| `adbc.spark.data_type_conv` | Comma-separated list of data conversion 
options. Each option indicates the type of conversion to perform on data 
returned from the Spark server. <br><br>Allowed values: `none`, `scalar`. 
<br><br>Option `none` indicates there is no conversion from Spark type to 
native type (i.e., no conversion from String to Timestamp for Apache Spark over 
HTTP). Example `adbc.spark.conv_data_type=none`. <br><br>Option `scalar` will 
perform conversion (if necessary) from the Spark data type to corresponding 
Arrow data types for types `DATE/Date32/DateTime`, 
`DECIMAL/Decimal128/SqlDecimal`, and `TIMESTAMP/Timestamp/DateTimeOffset`. 
Example `adbc.spark.conv_data_type=scalar` | `scalar` |

Review Comment:
   Document support for `scalar`.



##########
csharp/src/Drivers/Apache/Spark/SparkDatabricksConnection.cs:
##########
@@ -66,39 +79,5 @@ protected override Task<TRowSet> 
GetRowSetAsync(TGetCatalogsResp response) =>
             Task.FromResult(response.DirectResults.ResultSet.Results);
         protected override Task<TRowSet> GetRowSetAsync(TGetSchemasResp 
response) =>
             Task.FromResult(response.DirectResults.ResultSet.Results);
-
-        internal class DatabricksSchemaParser : SchemaParser

Review Comment:
   Refactored to its own file.



##########
csharp/src/Drivers/Apache/Spark/SparkParameters.cs:
##########
@@ -121,37 +121,4 @@ public enum SparkServerType
         HDInsight,
         Empty = int.MaxValue,
     }
-
-    public static class SparkDataTypeConversionConstants

Review Comment:
   Refactored to HiveServer2ConversionConstants to make available to Impala, 
etc.



##########
csharp/src/Drivers/Apache/Spark/SparkConnection.cs:
##########
@@ -998,8 +998,6 @@ protected static Uri GetBaseAddress(string? uri, string? 
hostName, string? path,
         protected abstract void ValidateAuthentication();
         protected abstract void ValidateOptions();
 
-        protected SparkDataTypeConversion DataTypeConversion = 
SparkDataTypeConversion.None;

Review Comment:
   Refactored to HiveServer2Connection.



##########
csharp/test/Drivers/Apache/Hive2/HiveServer2ParametersTest.cs:
##########
@@ -0,0 +1,59 @@
+/*
+* 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.Text;
+using System.Threading.Tasks;
+using Apache.Arrow.Adbc.Drivers.Apache.Hive2;
+using Xunit;
+
+namespace Apache.Arrow.Adbc.Tests.Drivers.Apache.Hive2
+{
+    public class HiveServer2ParametersTest
+    {
+        [SkippableTheory]
+        [MemberData(nameof(GetParametersTestData))]
+        public void TestParametersParse(string? dataTypeConversion, 
IReadOnlyCollection<HiveServer2DataTypeConversion> expected)

Review Comment:
   Test the parser returns expected results.



##########
csharp/src/Drivers/Apache/Spark/SparkHttpConnection.cs:
##########
@@ -248,39 +246,5 @@ internal static async Task<TFetchResultsResp> 
FetchNextAsync(TOperationHandle op
         internal override SchemaParser SchemaParser => new 
HiveServer2SchemaParser();
 
         internal override SparkServerType ServerType => SparkServerType.Http;
-
-        internal class HiveServer2SchemaParser : SchemaParser

Review Comment:
   Refactored to its own file.



##########
csharp/src/Drivers/Apache/Impala/ImpalaConnection.cs:
##########
@@ -84,8 +84,8 @@ public override IArrowArrayStream GetTableTypes()
 
         public override Schema GetTableSchema(string? catalog, string? 
dbSchema, string tableName) => throw new System.NotImplementedException();
 
-        internal override SchemaParser SchemaParser => throw new 
NotImplementedException();
+        internal override SchemaParser SchemaParser { get; } = new 
HiveServer2SchemaParser();

Review Comment:
   Support Impala queries.



##########
csharp/test/Apache.Arrow.Adbc.Tests/TestBase.cs:
##########
@@ -48,10 +48,10 @@ public abstract class TestBase<TConfig, TEnv> : IDisposable
         /// Constructs a new TestBase object with an output helper.
         /// </summary>
         /// <param name="outputHelper">Test output helper for writing test 
output.</param>
-        public TestBase(ITestOutputHelper? outputHelper, 
TestEnvironment<TConfig>.Factory<TEnv> testEnvFacltory)
+        public TestBase(ITestOutputHelper? outputHelper, 
TestEnvironment<TConfig>.Factory<TEnv> testEnvFactory)

Review Comment:
   Fixed type-o



##########
csharp/test/Drivers/Apache/Spark/SparkTestEnvironment.cs:
##########
@@ -47,9 +48,11 @@ public override string 
GetCreateTemporaryTableStatement(string tableName, string
             return string.Format("CREATE TABLE {0} ({1})", tableName, columns);
         }
 
-        public string? GetValueForProtocolVersion(string? hiveValue, string? 
databrickValue) => ServerType != SparkServerType.Databricks ? hiveValue : 
databrickValue;
+        public string? GetValueForProtocolVersion(string? hiveValue, string? 
databrickValue) =>
+            ServerType != SparkServerType.Databricks && 
((HiveServer2Connection)Connection).DataTypeConversion.Contains(HiveServer2DataTypeConversion.None)
 ? hiveValue : databrickValue;

Review Comment:
   Use the data type conversion option to help determine the expected type 
comparison.



##########
csharp/test/Drivers/Apache/Spark/SparkTestEnvironment.cs:
##########
@@ -101,7 +104,7 @@ public override Dictionary<string, string> 
GetDriverParameters(SparkTestConfigur
             return parameters;
         }
 
-        protected SparkServerType ServerType => 
((SparkConnection)Connection).ServerType;
+        public SparkServerType ServerType => 
((SparkConnection)Connection).ServerType;

Review Comment:
   Expose to tests.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to