You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "toddmeng-db (via GitHub)" <gi...@apache.org> on 2025/07/12 01:04:21 UTC
[PR] Parse decimal as Strings if not UseArrowNativeType [arrow-adbc]
toddmeng-db opened a new pull request, #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140
(no comment)
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2205971930
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -40,8 +64,8 @@ public override IArrowType GetArrowType(TPrimitiveTypeEntry thriftType, DataType
TTypeId.SMALLINT_TYPE => Int16Type.Default,
Review Comment:
Looks like this needs to stay as Timestamp_type, String actually does not work for that.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2205896361
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -40,8 +64,8 @@ public override IArrowType GetArrowType(TPrimitiveTypeEntry thriftType, DataType
TTypeId.SMALLINT_TYPE => Int16Type.Default,
Review Comment:
I have a feeling Timestamp type will also need to be String before Advanced Arrow type
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -40,8 +64,8 @@ public override IArrowType GetArrowType(TPrimitiveTypeEntry thriftType, DataType
TTypeId.SMALLINT_TYPE => Int16Type.Default,
Review Comment:
I have a feeling Timestamp type will also need to be String before Advanced Arrow type, investigating
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "jadewang-db (via GitHub)" <gi...@apache.org>.
jadewang-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2211887510
##########
csharp/src/Drivers/Databricks/DatabricksStatement.cs:
##########
@@ -64,10 +64,53 @@ public DatabricksStatement(DatabricksConnection connection)
enablePKFK = connection.EnablePKFK;
}
+ /// <summary>
+ /// Gets the schema from metadata response. Handles both Arrow schema (Protocol V5+) and traditional Thrift schema.
+ /// </summary>
+ /// <param name="metadata">The metadata response containing schema information</param>
+ /// <returns>The Arrow schema</returns>
+ protected override Schema GetSchemaFromMetadata(TGetResultSetMetadataResp metadata)
+ {
+ // For Protocol V5+, prefer Arrow schema if available
+ if (metadata.__isset.arrowSchema)
+ {
+ Schema? arrowSchema = ((DatabricksSchemaParser)Connection.SchemaParser).ParseArrowSchema(metadata.ArrowSchema);
+ if (arrowSchema != null)
+ {
+ return arrowSchema;
+ }
+ }
+
+ // Fallback to traditional Thrift schema
+ return Connection.SchemaParser.GetArrowSchema(metadata.Schema, Connection.DataTypeConversion);
+ }
+
protected override void SetStatementProperties(TExecuteStatementReq statement)
{
base.SetStatementProperties(statement);
+ // Set Databricks-specific statement properties
+ // TODO: Ensure this is set dynamically depending on server capabilities.
+ statement.EnforceResultPersistenceMode = false;
+ statement.ResultPersistenceMode = TResultPersistenceMode.ALL_RESULTS;
+ statement.CanReadArrowResult = true;
+
+#pragma warning disable CS0618 // Type or member is obsolete
+ statement.ConfOverlay = SparkConnection.timestampConfig;
+#pragma warning restore CS0618 // Type or member is obsolete
+
+ statement.UseArrowNativeTypes = new TSparkArrowTypes
+ {
+ TimestampAsArrow = true,
+ DecimalAsArrow = true,
+
+ // set to false so they return as string
+ // otherwise, they return as ARRAY_TYPE but you can't determine
+ // the object type of the items in the array
+ ComplexTypesAsArrow = false,
+ IntervalTypesAsArrow = false,
+ };
+
Review Comment:
what is the current odbc behavior? It's string? if we make it arrow, can powerbi handle?
##########
csharp/src/Drivers/Databricks/DatabricksStatement.cs:
##########
@@ -64,10 +64,53 @@ public DatabricksStatement(DatabricksConnection connection)
enablePKFK = connection.EnablePKFK;
}
+ /// <summary>
+ /// Gets the schema from metadata response. Handles both Arrow schema (Protocol V5+) and traditional Thrift schema.
+ /// </summary>
+ /// <param name="metadata">The metadata response containing schema information</param>
+ /// <returns>The Arrow schema</returns>
+ protected override Schema GetSchemaFromMetadata(TGetResultSetMetadataResp metadata)
+ {
+ // For Protocol V5+, prefer Arrow schema if available
+ if (metadata.__isset.arrowSchema)
+ {
+ Schema? arrowSchema = ((DatabricksSchemaParser)Connection.SchemaParser).ParseArrowSchema(metadata.ArrowSchema);
+ if (arrowSchema != null)
+ {
+ return arrowSchema;
+ }
+ }
+
+ // Fallback to traditional Thrift schema
+ return Connection.SchemaParser.GetArrowSchema(metadata.Schema, Connection.DataTypeConversion);
+ }
+
protected override void SetStatementProperties(TExecuteStatementReq statement)
{
base.SetStatementProperties(statement);
+ // Set Databricks-specific statement properties
+ // TODO: Ensure this is set dynamically depending on server capabilities.
+ statement.EnforceResultPersistenceMode = false;
+ statement.ResultPersistenceMode = TResultPersistenceMode.ALL_RESULTS;
+ statement.CanReadArrowResult = true;
+
+#pragma warning disable CS0618 // Type or member is obsolete
+ statement.ConfOverlay = SparkConnection.timestampConfig;
+#pragma warning restore CS0618 // Type or member is obsolete
+
+ statement.UseArrowNativeTypes = new TSparkArrowTypes
+ {
+ TimestampAsArrow = true,
+ DecimalAsArrow = true,
+
+ // set to false so they return as string
+ // otherwise, they return as ARRAY_TYPE but you can't determine
+ // the object type of the items in the array
+ ComplexTypesAsArrow = false,
+ IntervalTypesAsArrow = false,
+ };
+
Review Comment:
@CurtHagenlocher
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2205991832
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -40,8 +64,8 @@ public override IArrowType GetArrowType(TPrimitiveTypeEntry thriftType, DataType
TTypeId.SMALLINT_TYPE => Int16Type.Default,
Review Comment:
Seems like SQLConf.get.arrowThriftTimestampToString can be configured on OpenSessionReq, but we aren't doing that. Leaving a TODO here
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -40,8 +64,8 @@ public override IArrowType GetArrowType(TPrimitiveTypeEntry thriftType, DataType
TTypeId.SMALLINT_TYPE => Int16Type.Default,
Review Comment:
Seems like SQLConf.get.arrowThriftTimestampToString can be configured on OpenSessionReq, but we aren't doing that. Leaving a comment here
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "jadewang-db (via GitHub)" <gi...@apache.org>.
jadewang-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2211885712
##########
csharp/src/Drivers/Databricks/DatabricksStatement.cs:
##########
@@ -64,10 +64,53 @@ public DatabricksStatement(DatabricksConnection connection)
enablePKFK = connection.EnablePKFK;
}
+ /// <summary>
+ /// Gets the schema from metadata response. Handles both Arrow schema (Protocol V5+) and traditional Thrift schema.
+ /// </summary>
+ /// <param name="metadata">The metadata response containing schema information</param>
+ /// <returns>The Arrow schema</returns>
+ protected override Schema GetSchemaFromMetadata(TGetResultSetMetadataResp metadata)
+ {
+ // For Protocol V5+, prefer Arrow schema if available
+ if (metadata.__isset.arrowSchema)
+ {
+ Schema? arrowSchema = ((DatabricksSchemaParser)Connection.SchemaParser).ParseArrowSchema(metadata.ArrowSchema);
+ if (arrowSchema != null)
+ {
+ return arrowSchema;
+ }
+ }
+
+ // Fallback to traditional Thrift schema
+ return Connection.SchemaParser.GetArrowSchema(metadata.Schema, Connection.DataTypeConversion);
Review Comment:
are there any other place that this function being called independently?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2205877188
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -16,15 +16,39 @@
*/
using System;
+using System.IO;
using Apache.Arrow.Adbc.Drivers.Apache;
using Apache.Arrow.Adbc.Drivers.Apache.Hive2;
using Apache.Arrow.Types;
using Apache.Hive.Service.Rpc.Thrift;
+using Apache.Arrow.Ipc;
namespace Apache.Arrow.Adbc.Drivers.Databricks
{
internal class DatabricksSchemaParser : SchemaParser
Review Comment:
A bit new to Arrow, not 100% sure if this is the correct way to handle consuming ArrowSchema. In particular, runtime uses
```
MessageSerializer.serialize(writeChannel, getArrowSchema());
```
Which from what I understand can be correctly consumed using
```
using var stream = new MemoryStream(schemaBytes);
using var reader = new ArrowStreamReader(stream);~
```
Maybe @CurtHagenlocher @jadewang-db you may know better?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2205971930
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -40,8 +64,8 @@ public override IArrowType GetArrowType(TPrimitiveTypeEntry thriftType, DataType
TTypeId.SMALLINT_TYPE => Int16Type.Default,
Review Comment:
Looks like this needs to stay as Timestamp_type, String actually does not work for that.
Runtime:
```
case TType.TIMESTAMP_TYPE if SQLConf.get.arrowThriftTimestampToString =>
ArrowType.Utf8.INSTANCE
case TType.TIMESTAMP_TYPE =>
new ArrowType.Timestamp(TimeUnit.MICROSECOND, timeZoneId)
```
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2209050661
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -40,8 +64,8 @@ public override IArrowType GetArrowType(TPrimitiveTypeEntry thriftType, DataType
TTypeId.SMALLINT_TYPE => Int16Type.Default,
Review Comment:
Actually, looks like <dbr 7.0, we need Timestamp to be handled as a String, too. This is a bit different from what I expected just looking at runtime code...
This PR actually doesnt solve the issue, since dbr 7.0 - 10.0 does not actually get ArrowSchema. But they are both Datetime timestamps
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2207856121
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -16,15 +16,39 @@
*/
using System;
+using System.IO;
using Apache.Arrow.Adbc.Drivers.Apache;
using Apache.Arrow.Adbc.Drivers.Apache.Hive2;
using Apache.Arrow.Types;
using Apache.Hive.Service.Rpc.Thrift;
+using Apache.Arrow.Ipc;
namespace Apache.Arrow.Adbc.Drivers.Databricks
{
internal class DatabricksSchemaParser : SchemaParser
Review Comment:
It's become clear that we need to expose lower-level functions from the C# Arrow library to allow both schemas and data to be loaded independently of each other. This is probably the best option given the current APIs, but this approach and the `ChunkStream` approach used by `DatabricksReader` (as well as the `ReadRowsStream` used in the BigQuery driver) are less efficient than they could be if the lower-level functionality existed.
Tl;dr: this is correct.
##########
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:
I think it's a problem for a decimal table column to be returned as an Arrow string. We'll need to apply a conversion after reading the data. It's possible that when testing this scenario specifically with Power BI that things will work because the ADBC connector itself will (at least sometimes) convert the data to match the expected schema. However, this is a little inefficient and is clearly not the right behavior for the driver in non-Power BI contexts.
Broadly speaking, I think the right behavior here is for the driver to look at both the Thrift schema and the Arrow schema and to come up with a "final" schema as well as a collection of transformers to be applied to the individual columns. So if the Thrift schema says "decimal" and the Arrow schema says "string" then the final schema should say "decimal" and there should be a function to convert the string array into a decimal array.
##########
csharp/src/Drivers/Apache/Spark/SparkStatement.cs:
##########
@@ -32,28 +32,9 @@ internal SparkStatement(SparkConnection connection)
protected override void SetStatementProperties(TExecuteStatementReq statement)
{
Review Comment:
So (at least as of today) the OSS Spark implementation can't return results in Arrow format, only as Thrift?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2213774571
##########
csharp/src/Drivers/Databricks/DatabricksStatement.cs:
##########
@@ -64,10 +64,53 @@ public DatabricksStatement(DatabricksConnection connection)
enablePKFK = connection.EnablePKFK;
}
+ /// <summary>
+ /// Gets the schema from metadata response. Handles both Arrow schema (Protocol V5+) and traditional Thrift schema.
+ /// </summary>
+ /// <param name="metadata">The metadata response containing schema information</param>
+ /// <returns>The Arrow schema</returns>
+ protected override Schema GetSchemaFromMetadata(TGetResultSetMetadataResp metadata)
+ {
+ // For Protocol V5+, prefer Arrow schema if available
+ if (metadata.__isset.arrowSchema)
+ {
+ Schema? arrowSchema = ((DatabricksSchemaParser)Connection.SchemaParser).ParseArrowSchema(metadata.ArrowSchema);
+ if (arrowSchema != null)
+ {
+ return arrowSchema;
+ }
+ }
+
+ // Fallback to traditional Thrift schema
+ return Connection.SchemaParser.GetArrowSchema(metadata.Schema, Connection.DataTypeConversion);
Review Comment:
What do you mean?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2205991832
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -40,8 +64,8 @@ public override IArrowType GetArrowType(TPrimitiveTypeEntry thriftType, DataType
TTypeId.SMALLINT_TYPE => Int16Type.Default,
Review Comment:
Seems like SQLConf.get.arrowThriftTimestampToString can be configured on OpenSessionReq, but doesn't seem like we are doing that
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2213777685
##########
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:
Do you mean we want to do some conversion to thrift-type?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2229058657
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -40,8 +64,8 @@ public override IArrowType GetArrowType(TPrimitiveTypeEntry thriftType, DataType
TTypeId.SMALLINT_TYPE => Int16Type.Default,
Review Comment:
Ah, just realized its because { "spark.thriftserver.arrowBasedRowSet.timestampAsString", "false" }
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2209050661
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -40,8 +64,8 @@ public override IArrowType GetArrowType(TPrimitiveTypeEntry thriftType, DataType
TTypeId.SMALLINT_TYPE => Int16Type.Default,
Review Comment:
Actually, looks like <dbr 7.0, we need Timestamp to be handled as a String, too. This is a bit different from what I expected
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#issuecomment-3074824185
> Do you have a rough estimate for the percentage of compute instances whose versions would cause them to be impacted by these change?
It would certainly be a low, the vast majority of traffic is 10.0+ (and in Databricks documentation, dbr <10 is end-of-support). However, we do have non-trivial usage for lower versions like 9.1, 7.3 that we wouldn't want to break. Seems like the concern here is that decimal as-strings require some inefficient/hacky handling, and should ideally be converted in the driver?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Parse decimal as Strings for Older DBR [arrow-adbc]
Posted by "jadewang-db (via GitHub)" <gi...@apache.org>.
jadewang-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2205418727
##########
csharp/src/Drivers/Apache/Spark/SparkStatement.cs:
##########
@@ -32,28 +32,9 @@ internal SparkStatement(SparkConnection connection)
protected override void SetStatementProperties(TExecuteStatementReq statement)
{
- // TODO: Ensure this is set dynamically depending on server capabilities.
- statement.EnforceResultPersistenceMode = false;
- statement.ResultPersistenceMode = TResultPersistenceMode.ALL_RESULTS;
// This seems like a good idea to have the server timeout so it doesn't keep processing unnecessarily.
// Set in combination with a CancellationToken.
statement.QueryTimeout = QueryTimeoutSeconds;
- statement.CanReadArrowResult = true;
-
-#pragma warning disable CS0618 // Type or member is obsolete
- statement.ConfOverlay = SparkConnection.timestampConfig;
-#pragma warning restore CS0618 // Type or member is obsolete
- statement.UseArrowNativeTypes = new TSparkArrowTypes
- {
- TimestampAsArrow = true,
Review Comment:
may also keep this, and do data convertion base on result set schema and datatype in arrow stream
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2209050661
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -40,8 +64,8 @@ public override IArrowType GetArrowType(TPrimitiveTypeEntry thriftType, DataType
TTypeId.SMALLINT_TYPE => Int16Type.Default,
Review Comment:
Actually, looks like <dbr 7.0, we need Timestamp to be handled as a String, too. This is a bit different from what I expected just looking at runtime code...
This PR actually doesnt solve the issue, since dbr 7.0 - 10.0 does not actually get ArrowSchema.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher merged PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Parse decimal as Strings for Older DBR [arrow-adbc]
Posted by "jadewang-db (via GitHub)" <gi...@apache.org>.
jadewang-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2205417095
##########
csharp/src/Drivers/Apache/Spark/SparkStatement.cs:
##########
@@ -32,28 +32,9 @@ internal SparkStatement(SparkConnection connection)
protected override void SetStatementProperties(TExecuteStatementReq statement)
{
- // TODO: Ensure this is set dynamically depending on server capabilities.
- statement.EnforceResultPersistenceMode = false;
- statement.ResultPersistenceMode = TResultPersistenceMode.ALL_RESULTS;
// This seems like a good idea to have the server timeout so it doesn't keep processing unnecessarily.
// Set in combination with a CancellationToken.
statement.QueryTimeout = QueryTimeoutSeconds;
- statement.CanReadArrowResult = true;
-
-#pragma warning disable CS0618 // Type or member is obsolete
- statement.ConfOverlay = SparkConnection.timestampConfig;
-#pragma warning restore CS0618 // Type or member is obsolete
- statement.UseArrowNativeTypes = new TSparkArrowTypes
- {
- TimestampAsArrow = true,
- DecimalAsArrow = true,
-
- // set to false so they return as string
Review Comment:
I think we should still keep this?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2205855087
##########
csharp/src/Drivers/Apache/Spark/SparkStatement.cs:
##########
@@ -32,28 +32,9 @@ internal SparkStatement(SparkConnection connection)
protected override void SetStatementProperties(TExecuteStatementReq statement)
{
Review Comment:
moving this to the appropriate layer in DatabricksStatement, not directly related to this PR
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2209050661
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -40,8 +64,8 @@ public override IArrowType GetArrowType(TPrimitiveTypeEntry thriftType, DataType
TTypeId.SMALLINT_TYPE => Int16Type.Default,
Review Comment:
Actually, looks like <dbr 7.0, we need Timestamp to be handled as a String, too. This is a bit different from what I expected just looking at runtime code...
This PR actually doesnt solve the issue, since dbr 7.0 - 10.0 does not actually get ArrowSchema.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2208333096
##########
csharp/src/Drivers/Apache/Spark/SparkStatement.cs:
##########
@@ -32,28 +32,9 @@ internal SparkStatement(SparkConnection connection)
protected override void SetStatementProperties(TExecuteStatementReq statement)
{
Review Comment:
I think Spark via Hive-Thriftserver cannot. Those fields are also Databricks Spark-specific
##########
csharp/src/Drivers/Apache/Spark/SparkStatement.cs:
##########
@@ -32,28 +32,9 @@ internal SparkStatement(SparkConnection connection)
protected override void SetStatementProperties(TExecuteStatementReq statement)
{
Review Comment:
I think OSS Spark via Hive-Thriftserver cannot. Those fields are also Databricks Spark-specific
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "jadewang-db (via GitHub)" <gi...@apache.org>.
jadewang-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2211892472
##########
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:
agree with @CurtHagenlocher and this make me think, in GetSchemaFromMetadata should we really just return the arrow schema or we actually keep the thrift schema, we might want to confirm with runtime folks, if arrow schema is underlying dataschema we probably want to return the thrift schema as the result 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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2209050661
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -40,8 +64,8 @@ public override IArrowType GetArrowType(TPrimitiveTypeEntry thriftType, DataType
TTypeId.SMALLINT_TYPE => Int16Type.Default,
Review Comment:
Actually, looks like <dbr 7.0, we need Timestamp to be handled as a String, too. This is a bit different from what I expected just looking at runtime code...
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2205877188
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -16,15 +16,39 @@
*/
using System;
+using System.IO;
using Apache.Arrow.Adbc.Drivers.Apache;
using Apache.Arrow.Adbc.Drivers.Apache.Hive2;
using Apache.Arrow.Types;
using Apache.Hive.Service.Rpc.Thrift;
+using Apache.Arrow.Ipc;
namespace Apache.Arrow.Adbc.Drivers.Databricks
{
internal class DatabricksSchemaParser : SchemaParser
Review Comment:
A bit new to Arrow, not 100% sure if this is the correct way to handle consuming ArrowSchema (but this seems to work from manual testing). In particular, runtime populates ArrowSchema with
```
MessageSerializer.serialize(writeChannel, getArrowSchema());
```
Which from what I understand can be correctly consumed using
```
using var stream = new MemoryStream(schemaBytes);
using var reader = new ArrowStreamReader(stream);~
```
Maybe @CurtHagenlocher @jadewang-db you may know better?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2227030266
##########
csharp/src/Drivers/Apache/Hive2/HiveServer2Statement.cs:
##########
@@ -536,7 +546,7 @@ protected virtual async Task<QueryResult> GetColumnsAsync(CancellationToken canc
{
// Get data from direct results
Review Comment:
replaced all instances of consuming directly via schema to attempt to consume arrowschema first
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher commented on PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#issuecomment-3098031698
I would say that there are three different ways of thinking about this, depending on who the user is. For a new user who wants to consume Databricks data into their new C# application, I imagine they would want the loaded data to represent Spark's view of the data as closely as possible. This would include preserving type information and values with as much fidelity as the Arrow format allows. For a user who is currently consuming data into a .NET application* via ODBC, I suspect they would -- at least initially -- want the loaded data to be as similar as possible to what the ODBC driver is returning. (This doesn't line up perfectly for reasons I'll get into.) Finally, for use specifically inside Power BI the user would want to get the same results whether they're using the connector with ODBC or with ADBC. The latter two are (at least at first blush) pretty well-aligned**, because in both cases there's some client code that's switching from ODBC to ADBC for which we want to minim
ize the transition costs.
I'm not currently in a position to test the older server version via ODBC as I've had to decommission the Databricks instance I was using to test as it wasn't compliant with internal security restrictions, but I would be extremely surprised if it was returning decimal data as a string. And at a minimum, it would need to report the type of the result column as being decimal in order to let the client application know what type it is. But the difference is that ODBC is able to report the type as decimal while still retaining an internal representation of the data as a string. That's because fetching the data with ODBC specifically requires that you say what format you want it returned as. So even if the internal buffer contains a string, the client application would see that the column type is SQL_DECIMAL and it would say "I want this data formatted as SQL_C_DECIMAL" and the driver would need to perform any necessary conversion. This possibility doesn't exist with ADBC because there
is no similar distinction. The declared type has to be consistent with the type of the returned data buffer.
Earlier I had mentioned that the Power BI connector is doing some data/type translation. The context for this is that we ordinarily compute the expected type of the result set and then if the actual type doesn't match, the ADBC code in Power BI will inject a transformation. However, this only works when the user references tables in the catalog. In the scenario where the user supplies a native SQL query and we run it to discover the schema output, returning a decimal as string will mean that the original type is lost. This will make the data harder to work with in Power BI and would break backwards-compatibility.
Tl;dr: I'm afraid the driver will need to translate the data.
*Note that we still intend to make this driver work for non-.NET consumers by adding AOT compilation support. The main gap is some missing functionality in the core Arrow C# library for which there's a prototype implementation.
**That said, I think we'd love to be able to represent nested lists, records or tables in Power BI as their native types, because the conversion of all structured data into JSON is both lossy and limiting in terms of the kinds of querying we can do against the data source.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2213774571
##########
csharp/src/Drivers/Databricks/DatabricksStatement.cs:
##########
@@ -64,10 +64,53 @@ public DatabricksStatement(DatabricksConnection connection)
enablePKFK = connection.EnablePKFK;
}
+ /// <summary>
+ /// Gets the schema from metadata response. Handles both Arrow schema (Protocol V5+) and traditional Thrift schema.
+ /// </summary>
+ /// <param name="metadata">The metadata response containing schema information</param>
+ /// <returns>The Arrow schema</returns>
+ protected override Schema GetSchemaFromMetadata(TGetResultSetMetadataResp metadata)
+ {
+ // For Protocol V5+, prefer Arrow schema if available
+ if (metadata.__isset.arrowSchema)
+ {
+ Schema? arrowSchema = ((DatabricksSchemaParser)Connection.SchemaParser).ParseArrowSchema(metadata.ArrowSchema);
+ if (arrowSchema != null)
+ {
+ return arrowSchema;
+ }
+ }
+
+ // Fallback to traditional Thrift schema
+ return Connection.SchemaParser.GetArrowSchema(metadata.Schema, Connection.DataTypeConversion);
Review Comment:
Yes, I'll need to take a look at other places this is used
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Parse decimal as Strings for Older DBR [arrow-adbc]
Posted by "jadewang-db (via GitHub)" <gi...@apache.org>.
jadewang-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2205417095
##########
csharp/src/Drivers/Apache/Spark/SparkStatement.cs:
##########
@@ -32,28 +32,9 @@ internal SparkStatement(SparkConnection connection)
protected override void SetStatementProperties(TExecuteStatementReq statement)
{
- // TODO: Ensure this is set dynamically depending on server capabilities.
- statement.EnforceResultPersistenceMode = false;
- statement.ResultPersistenceMode = TResultPersistenceMode.ALL_RESULTS;
// This seems like a good idea to have the server timeout so it doesn't keep processing unnecessarily.
// Set in combination with a CancellationToken.
statement.QueryTimeout = QueryTimeoutSeconds;
- statement.CanReadArrowResult = true;
-
-#pragma warning disable CS0618 // Type or member is obsolete
- statement.ConfOverlay = SparkConnection.timestampConfig;
-#pragma warning restore CS0618 // Type or member is obsolete
- statement.UseArrowNativeTypes = new TSparkArrowTypes
- {
- TimestampAsArrow = true,
- DecimalAsArrow = true,
-
- // set to false so they return as string
Review Comment:
I think we should still keep this?
##########
csharp/src/Drivers/Apache/Spark/SparkStatement.cs:
##########
@@ -32,28 +32,9 @@ internal SparkStatement(SparkConnection connection)
protected override void SetStatementProperties(TExecuteStatementReq statement)
{
- // TODO: Ensure this is set dynamically depending on server capabilities.
- statement.EnforceResultPersistenceMode = false;
- statement.ResultPersistenceMode = TResultPersistenceMode.ALL_RESULTS;
// This seems like a good idea to have the server timeout so it doesn't keep processing unnecessarily.
// Set in combination with a CancellationToken.
statement.QueryTimeout = QueryTimeoutSeconds;
- statement.CanReadArrowResult = true;
-
-#pragma warning disable CS0618 // Type or member is obsolete
- statement.ConfOverlay = SparkConnection.timestampConfig;
-#pragma warning restore CS0618 // Type or member is obsolete
- statement.UseArrowNativeTypes = new TSparkArrowTypes
- {
- TimestampAsArrow = true,
Review Comment:
may also keep this, and do data convertion base on result set schema and datatype in arrow stream
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2205877188
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -16,15 +16,39 @@
*/
using System;
+using System.IO;
using Apache.Arrow.Adbc.Drivers.Apache;
using Apache.Arrow.Adbc.Drivers.Apache.Hive2;
using Apache.Arrow.Types;
using Apache.Hive.Service.Rpc.Thrift;
+using Apache.Arrow.Ipc;
namespace Apache.Arrow.Adbc.Drivers.Databricks
{
internal class DatabricksSchemaParser : SchemaParser
Review Comment:
A bit new to Arrow, not 100% sure if this is the correct way to handle consuming ArrowSchema. In particular, runtime populates ArrowSchema with
```
MessageSerializer.serialize(writeChannel, getArrowSchema());
```
Which from what I understand can be correctly consumed using
```
using var stream = new MemoryStream(schemaBytes);
using var reader = new ArrowStreamReader(stream);~
```
Maybe @CurtHagenlocher @jadewang-db you may know better?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2205971930
##########
csharp/src/Drivers/Databricks/DatabricksSchemaParser.cs:
##########
@@ -40,8 +64,8 @@ public override IArrowType GetArrowType(TPrimitiveTypeEntry thriftType, DataType
TTypeId.SMALLINT_TYPE => Int16Type.Default,
Review Comment:
Looks like this needs to stay as Timestamp_type, String actually does not work for that.
```
case TType.TIMESTAMP_TYPE if SQLConf.get.arrowThriftTimestampToString =>
ArrowType.Utf8.INSTANCE
case TType.TIMESTAMP_TYPE =>
new ArrowType.Timestamp(TimeUnit.MICROSECOND, timeZoneId)
```
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2208333096
##########
csharp/src/Drivers/Apache/Spark/SparkStatement.cs:
##########
@@ -32,28 +32,9 @@ internal SparkStatement(SparkConnection connection)
protected override void SetStatementProperties(TExecuteStatementReq statement)
{
Review Comment:
I think OSS Spark via Hive-Thriftserver cannot. Those fields are also Databricks-specific
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
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 Connector may do it's own conversion? If this didn't happen, what would the risk be?
> 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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Response Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#issuecomment-3112026759
@CurtHagenlocher I think we're considering going ahead and merging this, since we expect that this is still a correctness improvement and ArrowSchema should be the same for other types (that aren't in useArrowNativeTypes). We're still discussing internally how much effort we want to support for dbr < 10.4.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(csharp/src/Drivers/Databricks): Use ArrowSchema for Schema [arrow-adbc]
Posted by "toddmeng-db (via GitHub)" <gi...@apache.org>.
toddmeng-db commented on code in PR #3140:
URL: https://github.com/apache/arrow-adbc/pull/3140#discussion_r2205900738
##########
csharp/src/Drivers/Databricks/DatabricksStatement.cs:
##########
@@ -64,10 +64,53 @@ public DatabricksStatement(DatabricksConnection connection)
enablePKFK = connection.EnablePKFK;
}
+ /// <summary>
+ /// Gets the schema from metadata response. Handles both Arrow schema (Protocol V5+) and traditional Thrift schema.
+ /// </summary>
+ /// <param name="metadata">The metadata response containing schema information</param>
+ /// <returns>The Arrow schema</returns>
+ protected override Schema GetSchemaFromMetadata(TGetResultSetMetadataResp metadata)
+ {
+ // For Protocol V5+, prefer Arrow schema if available
+ if (metadata.__isset.arrowSchema)
+ {
+ Schema? arrowSchema = ((DatabricksSchemaParser)Connection.SchemaParser).ParseArrowSchema(metadata.ArrowSchema);
+ if (arrowSchema != null)
+ {
+ return arrowSchema;
+ }
+ }
+
+ // Fallback to traditional Thrift schema
+ return Connection.SchemaParser.GetArrowSchema(metadata.Schema, Connection.DataTypeConversion);
+ }
+
protected override void SetStatementProperties(TExecuteStatementReq statement)
{
base.SetStatementProperties(statement);
+ // Set Databricks-specific statement properties
+ // TODO: Ensure this is set dynamically depending on server capabilities.
+ statement.EnforceResultPersistenceMode = false;
+ statement.ResultPersistenceMode = TResultPersistenceMode.ALL_RESULTS;
+ statement.CanReadArrowResult = true;
+
+#pragma warning disable CS0618 // Type or member is obsolete
+ statement.ConfOverlay = SparkConnection.timestampConfig;
+#pragma warning restore CS0618 // Type or member is obsolete
+
+ statement.UseArrowNativeTypes = new TSparkArrowTypes
+ {
+ TimestampAsArrow = true,
+ DecimalAsArrow = true,
+
+ // set to false so they return as string
+ // otherwise, they return as ARRAY_TYPE but you can't determine
+ // the object type of the items in the array
+ ComplexTypesAsArrow = false,
+ IntervalTypesAsArrow = false,
+ };
+
Review Comment:
I have a feeling we can set these to true if we are using ArrowSchema now. Has there been any discussion about this?
cc @eric-wang-1990 @jadewang-db
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org