birschick-bq commented on code in PR #2559:
URL: https://github.com/apache/arrow-adbc/pull/2559#discussion_r1980428150
##########
csharp/src/Drivers/Apache/Spark/SparkDatabricksReader.cs:
##########
@@ -32,51 +35,64 @@ internal sealed class SparkDatabricksReader :
IArrowArrayStream
int index;
IArrowReader? reader;
- public SparkDatabricksReader(HiveServer2Statement statement, Schema
schema)
+ public SparkDatabricksReader(HiveServer2Statement statement, Schema
schema, ActivityTrace trace)
{
this.statement = statement;
this.schema = schema;
+ this.Trace = trace;
}
+ private ActivityTrace Trace { get; }
+
public Schema Schema { get { return schema; } }
public async ValueTask<RecordBatch?>
ReadNextRecordBatchAsync(CancellationToken cancellationToken = default)
{
- while (true)
+ return await Trace.TraceActivityAsync(async (activity) =>
{
- if (this.reader != null)
+ while (true)
{
- RecordBatch? next = await
this.reader.ReadNextRecordBatchAsync(cancellationToken);
- if (next != null)
+ if (this.reader != null)
{
- return next;
+ RecordBatch? next = await
this.reader.ReadNextRecordBatchAsync(cancellationToken);
+ if (next != null)
+ {
+ return next;
+ }
+ this.reader = null;
}
- 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;
- }
+ 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;
+ this.batches = null;
+ this.index = 0;
- if (this.statement == null)
- {
- return null;
- }
+ if (this.statement == null)
+ {
+ return null;
+ }
- TFetchResultsReq request = new
TFetchResultsReq(this.statement.OperationHandle, TFetchOrientation.FETCH_NEXT,
this.statement.BatchSize);
- TFetchResultsResp response = await
this.statement.Connection.Client!.FetchResults(request, cancellationToken);
- this.batches = response.Results.ArrowBatches;
+ activity?.AddEvent("db.operation.name.start",
[new("db.operation.name", nameof(Client.FetchResults))]);
+ TFetchResultsReq request = new
TFetchResultsReq(this.statement.OperationHandle, TFetchOrientation.FETCH_NEXT,
this.statement.BatchSize);
+ TFetchResultsResp response = await
this.statement.Connection.Client!.FetchResults(request, cancellationToken);
+ activity?.AddEvent("db.operation.name.end",
Review Comment:
Helps to trace the begin/end of fetching results from the server so the
duration can be calculated from the difference.
##########
csharp/src/Drivers/Apache/Hive2/HiveServer2Connection.cs:
##########
@@ -356,230 +367,268 @@ internal async Task OpenAsync()
internal abstract IArrowArrayStream NewReader<T>(T statement, Schema
schema) where T : HiveServer2Statement;
- public override IArrowArrayStream GetObjects(GetObjectsDepth depth,
string? catalogPattern, string? dbSchemaPattern, string? tableNamePattern,
IReadOnlyList<string>? tableTypes, string? columnNamePattern)
+ public override void SetOption(string key, string value)
{
- Dictionary<string, Dictionary<string, Dictionary<string,
TableInfo>>> catalogMap = new Dictionary<string, Dictionary<string,
Dictionary<string, TableInfo>>>();
- CancellationToken cancellationToken =
ApacheUtility.GetCancellationToken(QueryTimeoutSeconds,
ApacheUtility.TimeUnit.Seconds);
- try
+ switch (key.ToLowerInvariant())
{
- if (GetObjectsPatternsRequireLowerCase)
- {
- catalogPattern = catalogPattern?.ToLower();
- dbSchemaPattern = dbSchemaPattern?.ToLower();
- tableNamePattern = tableNamePattern?.ToLower();
- columnNamePattern = columnNamePattern?.ToLower();
- }
- if (depth == GetObjectsDepth.All || depth >=
GetObjectsDepth.Catalogs)
- {
- TGetCatalogsReq getCatalogsReq = new
TGetCatalogsReq(SessionHandle);
- if (AreResultsAvailableDirectly())
- {
- SetDirectResults(getCatalogsReq);
- }
-
- TGetCatalogsResp getCatalogsResp =
Client.GetCatalogs(getCatalogsReq, cancellationToken).Result;
+ // Since this API only allows non-null values, we'll treat
empty string as null to allow the TraceParent to be unset.
+ case HiveServer2Parameters.TraceParent:
+ Trace.TraceParent = !string.IsNullOrWhiteSpace(value)
Review Comment:
Allow the caller to set the `trace_parent` on the connection.
##########
csharp/src/Drivers/Apache/Hive2/HiveServer2Driver.cs:
##########
@@ -16,14 +16,28 @@
*/
using System.Collections.Generic;
+using Apache.Arrow.Adbc.Tracing;
namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2
{
public class HiveServer2Driver : AdbcDriver
{
+ public HiveServer2Driver(string? activitySourceName = default, string?
traceParent = default)
+ {
+ Trace = new ActivityTrace(activitySourceName, traceParent);
+ }
+
public override AdbcDatabase Open(IReadOnlyDictionary<string, string>
parameters)
{
- return new HiveServer2Database(parameters);
+ return new HiveServer2Database(parameters, Trace);
Review Comment:
Passing reference to `Trace` object to child object for consistent activity
source name and handling of trace parent.
##########
csharp/src/Apache.Arrow.Adbc/Tracing/SerializableActivity.cs:
##########
@@ -0,0 +1,192 @@
+/*
+ * 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.Diagnostics;
+using System.Linq;
+using System.Text.Json.Serialization;
+
+namespace Apache.Arrow.Adbc.Tracing
+{
+ /// <summary>
+ /// Simplified version of <see cref="Activity"/> that excludes some
properties, etc.
+ /// </summary>
+ internal class SerializableActivity
Review Comment:
This class is explicitly necessary, but helps with testing. It also "could"
be useful a serialized version of `Activity`
--
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]