toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2214598029
##########
csharp/test/Drivers/Databricks/E2E/StatementTests.cs:
##########
@@ -1279,5 +1279,80 @@ public async Task
OlderDBRVersion_ShouldSetSchemaViaUseStatement()
Assert.True(foundSchemas.Count == 1, "Should have exactly one
schema");
}
+ [SkippableTheory]
+ [InlineData("cast(-6 as decimal(3, 1))", "-6.0", 3, 1, "Negative
decimal with scale")]
+ [InlineData("cast(0 as decimal(1, 0))", "0", 1, 0, "Zero decimal")]
+ [InlineData("cast(123 as decimal(3, 0))", "123", 3, 0, "Positive
integer decimal")]
+ [InlineData("cast(123456789.123456789 as decimal(18, 9))",
"123456789.123456789", 18, 9, "High precision decimal")]
+ [InlineData("cast(-123456789.123456789 as decimal(18, 9))",
"-123456789.123456789", 18, 9, "High precision negative decimal")]
+ public async Task CanExecuteDecimalQuery(string sqlExpression, string
expectedValueString, int expectedPrecision, int expectedScale, string
testDescription)
+ {
+ decimal expectedValue = decimal.Parse(expectedValueString);
+ // This tests the bug where older DBR versions return decimal
values as strings when UseArrowNativeTypes is false
+ // To repro issue, run this with dbr < 10.0
+ OutputHelper?.WriteLine($"Testing: {testDescription}");
+ OutputHelper?.WriteLine($"SQL Expression: {sqlExpression}");
+ OutputHelper?.WriteLine($"Expected Value: {expectedValue}");
+ OutputHelper?.WriteLine($"Expected Precision: {expectedPrecision},
Scale: {expectedScale}");
+
+ using AdbcConnection connection = NewConnection();
+ using var statement = connection.CreateStatement();
+
+ // Use the provided SQL expression
+ statement.SqlQuery = $"SELECT {sqlExpression} as A";
+ QueryResult result = statement.ExecuteQuery();
+
+ Assert.NotNull(result.Stream);
+
+ // Verify the schema
+ var schema = result.Stream.Schema;
+ Assert.Single(schema.FieldsList);
+
+ var field = schema.GetFieldByName("A");
+ Assert.NotNull(field);
+
+ OutputHelper?.WriteLine($"Decimal field type:
{field.DataType.GetType().Name}");
+ OutputHelper?.WriteLine($"Decimal field type ID:
{field.DataType.TypeId}");
+
+ // Read the actual data
+ var batch = await result.Stream.ReadNextRecordBatchAsync();
+ Assert.NotNull(batch);
+ Assert.Equal(1, batch.Length);
+
+ if (field.DataType is Decimal128Type decimalType)
+ {
+ // For newer DBR versions with UseArrowNativeTypes enabled,
decimal is returned as Decimal128Type
+ Assert.Equal(expectedPrecision, decimalType.Precision);
+ Assert.Equal(expectedScale, decimalType.Scale);
+
+ var col0 = batch.Column(0) as Decimal128Array;
+ Assert.NotNull(col0);
+ Assert.Equal(1, col0.Length);
+
+ var sqlDecimal = col0.GetSqlDecimal(0);
+ Assert.NotNull(sqlDecimal);
+ Assert.Equal(expectedValue, sqlDecimal.Value);
+
+ OutputHelper?.WriteLine($"Decimal value: {sqlDecimal.Value}
(precision: {decimalType.Precision}, scale: {decimalType.Scale})");
+ }
+ else if (field.DataType is StringType)
Review Comment:
@CurtHagenlocher what would the risk be if we returned a Arrow String here,
instead of an Arrow Decimal? You said PowerBi/Connector may do it's own
conversion?
> ADBC connector itself will (at least sometimes) convert the data to match
the expected schema
--
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]