forked from apache/arrow-adbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHiveServer2Statement.cs
560 lines (492 loc) · 26.9 KB
/
HiveServer2Statement.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
/*
* 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.Threading;
using System.Threading.Tasks;
using Apache.Arrow.Ipc;
using Apache.Arrow.Types;
using Apache.Hive.Service.Rpc.Thrift;
using Thrift.Transport;
namespace Apache.Arrow.Adbc.Drivers.Apache.Hive2
{
internal class HiveServer2Statement : AdbcStatement
{
private const string GetPrimaryKeysCommandName = "getprimarykeys";
private const string GetCrossReferenceCommandName = "getcrossreference";
private const string GetCatalogsCommandName = "getcatalogs";
private const string GetSchemasCommandName = "getschemas";
private const string GetTablesCommandName = "gettables";
private const string GetColumnsCommandName = "getcolumns";
private const string SupportedMetadataCommands =
GetCatalogsCommandName + "," +
GetSchemasCommandName + "," +
GetTablesCommandName + "," +
GetColumnsCommandName + "," +
GetPrimaryKeysCommandName + "," +
GetCrossReferenceCommandName;
internal HiveServer2Statement(HiveServer2Connection connection)
{
Connection = connection;
ValidateOptions(connection.Properties);
}
protected virtual void SetStatementProperties(TExecuteStatementReq statement)
{
statement.QueryTimeout = QueryTimeoutSeconds;
}
public override QueryResult ExecuteQuery()
{
CancellationToken cancellationToken = ApacheUtility.GetCancellationToken(QueryTimeoutSeconds, ApacheUtility.TimeUnit.Seconds);
try
{
return ExecuteQueryAsyncInternal(cancellationToken).Result;
}
catch (Exception ex)
when (ApacheUtility.ContainsException(ex, out OperationCanceledException? _) ||
(ApacheUtility.ContainsException(ex, out TTransportException? _) && cancellationToken.IsCancellationRequested))
{
throw new TimeoutException("The query execution timed out. Consider increasing the query timeout value.", ex);
}
catch (Exception ex) when (ex is not HiveServer2Exception)
{
throw new HiveServer2Exception($"An unexpected error occurred while fetching results. '{ex.Message}'", ex);
}
}
public override UpdateResult ExecuteUpdate()
{
CancellationToken cancellationToken = ApacheUtility.GetCancellationToken(QueryTimeoutSeconds, ApacheUtility.TimeUnit.Seconds);
try
{
return ExecuteUpdateAsyncInternal(cancellationToken).Result;
}
catch (Exception ex)
when (ApacheUtility.ContainsException(ex, out OperationCanceledException? _) ||
(ApacheUtility.ContainsException(ex, out TTransportException? _) && cancellationToken.IsCancellationRequested))
{
throw new TimeoutException("The query execution timed out. Consider increasing the query timeout value.", ex);
}
catch (Exception ex) when (ex is not HiveServer2Exception)
{
throw new HiveServer2Exception($"An unexpected error occurred while fetching results. '{ex.Message}'", ex);
}
}
private async Task<QueryResult> ExecuteQueryAsyncInternal(CancellationToken cancellationToken = default)
{
if (IsMetadataCommand)
{
return await ExecuteMetadataCommandQuery(cancellationToken);
}
// this could either:
// take QueryTimeoutSeconds * 3
// OR
// take QueryTimeoutSeconds (but this could be restricting)
await ExecuteStatementAsync(cancellationToken); // --> get QueryTimeout +
await HiveServer2Connection.PollForResponseAsync(OperationHandle!, Connection.Client, PollTimeMilliseconds, cancellationToken); // + poll, up to QueryTimeout
TGetResultSetMetadataResp response = await HiveServer2Connection.GetResultSetMetadataAsync(OperationHandle!, Connection.Client, cancellationToken);
Schema schema = Connection.SchemaParser.GetArrowSchema(response.Schema, Connection.DataTypeConversion);
// Store metadata for use in readers
return new QueryResult(-1, Connection.NewReader(this, schema, response));
}
public override async ValueTask<QueryResult> ExecuteQueryAsync()
{
CancellationToken cancellationToken = ApacheUtility.GetCancellationToken(QueryTimeoutSeconds, ApacheUtility.TimeUnit.Seconds);
try
{
return await ExecuteQueryAsyncInternal(cancellationToken);
}
catch (Exception ex)
when (ApacheUtility.ContainsException(ex, out OperationCanceledException? _) ||
(ApacheUtility.ContainsException(ex, out TTransportException? _) && cancellationToken.IsCancellationRequested))
{
throw new TimeoutException("The query execution timed out. Consider increasing the query timeout value.", ex);
}
catch (Exception ex) when (ex is not HiveServer2Exception)
{
throw new HiveServer2Exception($"An unexpected error occurred while fetching results. '{ex.Message}'", ex);
}
}
public async Task<UpdateResult> ExecuteUpdateAsyncInternal(CancellationToken cancellationToken = default)
{
const string NumberOfAffectedRowsColumnName = "num_affected_rows";
QueryResult queryResult = await ExecuteQueryAsyncInternal(cancellationToken);
if (queryResult.Stream == null)
{
throw new AdbcException("no data found");
}
using IArrowArrayStream stream = queryResult.Stream;
// Check if the affected rows columns are returned in the result.
Field affectedRowsField = stream.Schema.GetFieldByName(NumberOfAffectedRowsColumnName);
if (affectedRowsField != null && affectedRowsField.DataType.TypeId != Types.ArrowTypeId.Int64)
{
throw new AdbcException($"Unexpected data type for column: '{NumberOfAffectedRowsColumnName}'", new ArgumentException(NumberOfAffectedRowsColumnName));
}
// The default is -1.
if (affectedRowsField == null) return new UpdateResult(-1);
long? affectedRows = null;
while (true)
{
using RecordBatch nextBatch = await stream.ReadNextRecordBatchAsync(cancellationToken);
if (nextBatch == null) { break; }
Int64Array numOfModifiedArray = (Int64Array)nextBatch.Column(NumberOfAffectedRowsColumnName);
// Note: should only have one item, but iterate for completeness
for (int i = 0; i < numOfModifiedArray.Length; i++)
{
// Note: handle the case where the affected rows are zero (0).
affectedRows = (affectedRows ?? 0) + numOfModifiedArray.GetValue(i).GetValueOrDefault(0);
}
}
// If no altered rows, i.e. DDC statements, then -1 is the default.
return new UpdateResult(affectedRows ?? -1);
}
public override async Task<UpdateResult> ExecuteUpdateAsync()
{
CancellationToken cancellationToken = ApacheUtility.GetCancellationToken(QueryTimeoutSeconds, ApacheUtility.TimeUnit.Seconds);
try
{
return await ExecuteUpdateAsyncInternal(cancellationToken);
}
catch (Exception ex)
when (ApacheUtility.ContainsException(ex, out OperationCanceledException? _) ||
(ApacheUtility.ContainsException(ex, out TTransportException? _) && cancellationToken.IsCancellationRequested))
{
throw new TimeoutException("The query execution timed out. Consider increasing the query timeout value.", ex);
}
catch (Exception ex) when (ex is not HiveServer2Exception)
{
throw new HiveServer2Exception($"An unexpected error occurred while fetching results. '{ex.Message}'", ex);
}
}
public override void SetOption(string key, string value)
{
switch (key)
{
case ApacheParameters.PollTimeMilliseconds:
UpdatePollTimeIfValid(key, value);
break;
case ApacheParameters.BatchSize:
UpdateBatchSizeIfValid(key, value);
break;
case ApacheParameters.QueryTimeoutSeconds:
if (ApacheUtility.QueryTimeoutIsValid(key, value, out int queryTimeoutSeconds))
{
QueryTimeoutSeconds = queryTimeoutSeconds;
}
break;
case ApacheParameters.IsMetadataCommand:
if (ApacheUtility.BooleanIsValid(key, value, out bool isMetadataCommand))
{
IsMetadataCommand = isMetadataCommand;
}
break;
case ApacheParameters.CatalogName:
this.CatalogName = value;
break;
case ApacheParameters.SchemaName:
this.SchemaName = value;
break;
case ApacheParameters.TableName:
this.TableName = value;
break;
case ApacheParameters.TableTypes:
this.TableTypes = value;
break;
case ApacheParameters.ColumnName:
this.ColumnName = value;
break;
case ApacheParameters.ForeignCatalogName:
this.ForeignCatalogName = value;
break;
case ApacheParameters.ForeignSchemaName:
this.ForeignSchemaName = value;
break;
case ApacheParameters.ForeignTableName:
this.ForeignTableName = value;
break;
default:
throw AdbcException.NotImplemented($"Option '{key}' is not implemented.");
}
}
protected async Task ExecuteStatementAsync(CancellationToken cancellationToken = default)
{
if (Connection.SessionHandle == null)
{
throw new InvalidOperationException("Invalid session");
}
TExecuteStatementReq executeRequest = new TExecuteStatementReq(Connection.SessionHandle, SqlQuery!);
SetStatementProperties(executeRequest);
TExecuteStatementResp executeResponse = await Connection.Client.ExecuteStatement(executeRequest, cancellationToken);
if (executeResponse.Status.StatusCode == TStatusCode.ERROR_STATUS)
{
throw new HiveServer2Exception(executeResponse.Status.ErrorMessage)
.SetSqlState(executeResponse.Status.SqlState)
.SetNativeError(executeResponse.Status.ErrorCode);
}
OperationHandle = executeResponse.OperationHandle;
}
protected internal int PollTimeMilliseconds { get; private set; } = HiveServer2Connection.PollTimeMillisecondsDefault;
protected internal long BatchSize { get; private set; } = HiveServer2Connection.BatchSizeDefault;
protected internal int QueryTimeoutSeconds
{
// Coordinate updates with the connection
get => Connection.QueryTimeoutSeconds;
set => Connection.QueryTimeoutSeconds = value;
}
protected internal bool IsMetadataCommand { get; set; } = false;
protected internal string? CatalogName { get; set; }
protected internal string? SchemaName { get; set; }
protected internal string? TableName { get; set; }
protected internal string? TableTypes { get; set; }
protected internal string? ColumnName { get; set; }
protected internal string? ForeignCatalogName { get; set; }
protected internal string? ForeignSchemaName { get; set; }
protected internal string? ForeignTableName { get; set; }
public HiveServer2Connection Connection { get; private set; }
public TOperationHandle? OperationHandle { get; private set; }
private void UpdatePollTimeIfValid(string key, string value) => PollTimeMilliseconds = !string.IsNullOrEmpty(key) && int.TryParse(value, result: out int pollTimeMilliseconds) && pollTimeMilliseconds >= 0
? pollTimeMilliseconds
: throw new ArgumentOutOfRangeException(key, value, $"The value '{value}' for option '{key}' is invalid. Must be a numeric value greater than or equal to 0.");
private void UpdateBatchSizeIfValid(string key, string value) => BatchSize = !string.IsNullOrEmpty(value) && long.TryParse(value, out long batchSize) && batchSize > 0
? batchSize
: throw new ArgumentOutOfRangeException(key, value, $"The value '{value}' for option '{key}' is invalid. Must be a numeric value greater than zero.");
public override void Dispose()
{
if (OperationHandle != null)
{
CancellationToken cancellationToken = ApacheUtility.GetCancellationToken(QueryTimeoutSeconds, ApacheUtility.TimeUnit.Seconds);
TCloseOperationReq request = new TCloseOperationReq(OperationHandle);
Connection.Client.CloseOperation(request, cancellationToken).Wait();
OperationHandle = null;
}
base.Dispose();
}
protected void ValidateOptions(IReadOnlyDictionary<string, string> properties)
{
foreach (KeyValuePair<string, string> kvp in properties)
{
switch (kvp.Key)
{
case ApacheParameters.BatchSize:
case ApacheParameters.PollTimeMilliseconds:
case ApacheParameters.QueryTimeoutSeconds:
{
SetOption(kvp.Key, kvp.Value);
break;
}
}
}
}
private async Task<QueryResult> ExecuteMetadataCommandQuery(CancellationToken cancellationToken)
{
return SqlQuery?.ToLowerInvariant() switch
{
GetCatalogsCommandName => await GetCatalogsAsync(cancellationToken),
GetSchemasCommandName => await GetSchemasAsync(cancellationToken),
GetTablesCommandName => await GetTablesAsync(cancellationToken),
GetColumnsCommandName => await GetColumnsAsync(cancellationToken),
GetPrimaryKeysCommandName => await GetPrimaryKeysAsync(cancellationToken),
GetCrossReferenceCommandName => await GetCrossReferenceAsync(cancellationToken),
null or "" => throw new ArgumentNullException(nameof(SqlQuery), $"Metadata command for property 'SqlQuery' must not be empty or null. Supported metadata commands: {SupportedMetadataCommands}"),
_ => throw new NotSupportedException($"Metadata command '{SqlQuery}' is not supported. Supported metadata commands: {SupportedMetadataCommands}"),
};
}
private async Task<QueryResult> GetCrossReferenceAsync(CancellationToken cancellationToken = default)
{
TGetCrossReferenceResp resp = await Connection.GetCrossReferenceAsync(
CatalogName,
SchemaName,
TableName,
ForeignCatalogName,
ForeignSchemaName,
ForeignTableName,
cancellationToken);
OperationHandle = resp.OperationHandle;
return await GetQueryResult(resp.DirectResults, cancellationToken);
}
private async Task<QueryResult> GetPrimaryKeysAsync(CancellationToken cancellationToken = default)
{
TGetPrimaryKeysResp resp = await Connection.GetPrimaryKeysAsync(
CatalogName,
SchemaName,
TableName,
cancellationToken);
OperationHandle = resp.OperationHandle;
return await GetQueryResult(resp.DirectResults, cancellationToken);
}
private async Task<QueryResult> GetCatalogsAsync(CancellationToken cancellationToken = default)
{
TGetCatalogsResp resp = await Connection.GetCatalogsAsync(cancellationToken);
OperationHandle = resp.OperationHandle;
return await GetQueryResult(resp.DirectResults, cancellationToken);
}
private async Task<QueryResult> GetSchemasAsync(CancellationToken cancellationToken = default)
{
TGetSchemasResp resp = await Connection.GetSchemasAsync(
CatalogName,
SchemaName,
cancellationToken);
OperationHandle = resp.OperationHandle;
return await GetQueryResult(resp.DirectResults, cancellationToken);
}
private async Task<QueryResult> GetTablesAsync(CancellationToken cancellationToken = default)
{
List<string>? tableTypesList = this.TableTypes?.Split(',').ToList();
TGetTablesResp resp = await Connection.GetTablesAsync(
CatalogName,
SchemaName,
TableName,
tableTypesList,
cancellationToken);
OperationHandle = resp.OperationHandle;
return await GetQueryResult(resp.DirectResults, cancellationToken);
}
private async Task<QueryResult> GetColumnsAsync(CancellationToken cancellationToken = default)
{
TGetColumnsResp resp = await Connection.GetColumnsAsync(
CatalogName,
SchemaName,
TableName,
ColumnName,
cancellationToken);
OperationHandle = resp.OperationHandle;
// For GetColumns, we need to enhance the result with BASE_TYPE_NAME
if (Connection.AreResultsAvailableDirectly() && resp.DirectResults?.ResultSet?.Results != null)
{
TGetResultSetMetadataResp resultSetMetadata = resp.DirectResults.ResultSetMetadata;
Schema schema = Connection.SchemaParser.GetArrowSchema(resultSetMetadata.Schema, Connection.DataTypeConversion);
TRowSet rowSet = resp.DirectResults.ResultSet.Results;
int columnCount = HiveServer2Reader.GetColumnCount(rowSet);
int rowCount = HiveServer2Reader.GetRowCount(rowSet, columnCount);
IReadOnlyList<IArrowArray> data = HiveServer2Reader.GetArrowArrayData(rowSet, columnCount, schema, Connection.DataTypeConversion);
return EnhanceGetColumnsResult(schema, data, rowCount, resultSetMetadata, rowSet);
}
else
{
await HiveServer2Connection.PollForResponseAsync(OperationHandle!, Connection.Client, PollTimeMilliseconds, cancellationToken);
Schema schema = await GetResultSetSchemaAsync(OperationHandle!, Connection.Client, cancellationToken);
// Fetch the results manually to enhance them
TRowSet rowSet = await Connection.FetchResultsAsync(OperationHandle!, BatchSize, cancellationToken);
int columnCount = HiveServer2Reader.GetColumnCount(rowSet);
int rowCount = HiveServer2Reader.GetRowCount(rowSet, columnCount);
// Get metadata again to ensure we have the latest
TGetResultSetMetadataResp metadata = await HiveServer2Connection.GetResultSetMetadataAsync(OperationHandle!, Connection.Client, cancellationToken);
// Get the arrays from the row set
IReadOnlyList<IArrowArray> data = HiveServer2Reader.GetArrowArrayData(rowSet, columnCount, schema, Connection.DataTypeConversion);
return EnhanceGetColumnsResult(schema, data, rowCount, metadata, rowSet);
}
}
private async Task<Schema> GetResultSetSchemaAsync(TOperationHandle operationHandle, TCLIService.IAsync client, CancellationToken cancellationToken = default)
{
TGetResultSetMetadataResp response = await HiveServer2Connection.GetResultSetMetadataAsync(operationHandle, client, cancellationToken);
return Connection.SchemaParser.GetArrowSchema(response.Schema, Connection.DataTypeConversion);
}
private async Task<QueryResult> GetQueryResult(TSparkDirectResults? directResults, CancellationToken cancellationToken)
{
Schema schema;
if (Connection.AreResultsAvailableDirectly() && directResults?.ResultSet?.Results != null)
{
TGetResultSetMetadataResp resultSetMetadata = directResults.ResultSetMetadata;
schema = Connection.SchemaParser.GetArrowSchema(resultSetMetadata.Schema, Connection.DataTypeConversion);
TRowSet rowSet = directResults.ResultSet.Results;
int columnCount = HiveServer2Reader.GetColumnCount(rowSet);
int rowCount = HiveServer2Reader.GetRowCount(rowSet, columnCount);
IReadOnlyList<IArrowArray> data = HiveServer2Reader.GetArrowArrayData(rowSet, columnCount, schema, Connection.DataTypeConversion);
return new QueryResult(rowCount, new HiveServer2Connection.HiveInfoArrowStream(schema, data));
}
await HiveServer2Connection.PollForResponseAsync(OperationHandle!, Connection.Client, PollTimeMilliseconds, cancellationToken);
schema = await GetResultSetSchemaAsync(OperationHandle!, Connection.Client, cancellationToken);
return new QueryResult(-1, Connection.NewReader(this, schema));
}
protected internal QueryResult EnhanceGetColumnsResult(Schema originalSchema, IReadOnlyList<IArrowArray> originalData,
int rowCount, TGetResultSetMetadataResp metadata, TRowSet rowSet)
{
// Create a column map using Connection's GetColumnIndexMap method
var columnMap = Connection.GetColumnIndexMap(metadata.Schema.Columns);
// Get column indices - we know these columns always exist
int typeNameIndex = columnMap["TYPE_NAME"];
int dataTypeIndex = columnMap["DATA_TYPE"];
int columnSizeIndex = columnMap["COLUMN_SIZE"];
int decimalDigitsIndex = columnMap["DECIMAL_DIGITS"];
// Extract the existing arrays
StringArray typeNames = (StringArray)originalData[typeNameIndex];
Int32Array originalColumnSizes = (Int32Array)originalData[columnSizeIndex];
Int32Array originalDecimalDigits = (Int32Array)originalData[decimalDigitsIndex];
// Create enhanced schema with BASE_TYPE_NAME column
var enhancedFields = originalSchema.FieldsList.ToList();
enhancedFields.Add(new Field("BASE_TYPE_NAME", StringType.Default, true));
Schema enhancedSchema = new Schema(enhancedFields, originalSchema.Metadata);
// Pre-allocate arrays to store our values
int length = typeNames.Length;
List<string> baseTypeNames = new List<string>(length);
List<int> columnSizeValues = new List<int>(length);
List<int> decimalDigitsValues = new List<int>(length);
// Process each row
for (int i = 0; i < length; i++)
{
string? typeName = typeNames.GetString(i);
short colType = (short)rowSet.Columns[dataTypeIndex].I32Val.Values.Values[i];
int columnSize = originalColumnSizes.GetValue(i).GetValueOrDefault();
int decimalDigits = originalDecimalDigits.GetValue(i).GetValueOrDefault();
// Create a TableInfo for this row
var tableInfo = new HiveServer2Connection.TableInfo(string.Empty);
// Process all types through SetPrecisionScaleAndTypeName
Connection.SetPrecisionScaleAndTypeName(colType, typeName ?? string.Empty, tableInfo, columnSize, decimalDigits);
// Get base type name
string baseTypeName;
if (tableInfo.BaseTypeName.Count > 0)
{
string? baseTypeNameValue = tableInfo.BaseTypeName[0];
baseTypeName = baseTypeNameValue ?? string.Empty;
}
else
{
baseTypeName = typeName ?? string.Empty;
}
baseTypeNames.Add(baseTypeName);
// Get precision/scale values
if (tableInfo.Precision.Count > 0)
{
int? precisionValue = tableInfo.Precision[0];
columnSizeValues.Add(precisionValue.GetValueOrDefault(columnSize));
}
else
{
columnSizeValues.Add(columnSize);
}
if (tableInfo.Scale.Count > 0)
{
int? scaleValue = tableInfo.Scale[0];
decimalDigitsValues.Add(scaleValue.GetValueOrDefault(decimalDigits));
}
else
{
decimalDigitsValues.Add(decimalDigits);
}
}
// Create the Arrow arrays directly from our data arrays
StringArray baseTypeNameArray = new StringArray.Builder().AppendRange(baseTypeNames).Build();
Int32Array columnSizeArray = new Int32Array.Builder().AppendRange(columnSizeValues).Build();
Int32Array decimalDigitsArray = new Int32Array.Builder().AppendRange(decimalDigitsValues).Build();
// Create enhanced data with modified columns
var enhancedData = new List<IArrowArray>(originalData);
enhancedData[columnSizeIndex] = columnSizeArray;
enhancedData[decimalDigitsIndex] = decimalDigitsArray;
enhancedData.Add(baseTypeNameArray);
return new QueryResult(rowCount, new HiveServer2Connection.HiveInfoArrowStream(enhancedSchema, enhancedData));
}
}
}