Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(csharp/src/Drivers/Apache): fix float data type handling for tests on Databricks Spark #2283

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions csharp/test/Drivers/Apache/Spark/SparkTestEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ public override string GetInsertStatement(string tableName, string columnName, s
public override SampleDataBuilder GetSampleDataBuilder()
{
SampleDataBuilder sampleDataBuilder = new();
Type floatNetType = ServerType == SparkServerType.Databricks ? typeof(float) : typeof(double);
Type floatArrowType = ServerType == SparkServerType.Databricks ? typeof(FloatType) : typeof(DoubleType);
object floatValue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle, it probably should be float for both. I imagine the reason we get doubles via Thrift is that TColumn doesn't define a TFloatColumn, only a TDoubleColumn. But if we know from the schema that it should be a float then we should probably be doing a conversion in the driver.

if (ServerType == SparkServerType.Databricks)
floatValue = 1f;
else
floatValue = 1d;

// standard values
sampleDataBuilder.Samples.Add(
Expand All @@ -147,7 +154,7 @@ public override SampleDataBuilder GetSampleDataBuilder()
Query = "SELECT " +
"CAST(1 as BIGINT) as id, " +
"CAST(2 as INTEGER) as int, " +
"CAST(1.23 as FLOAT) as number_float, " +
"CAST(1 as FLOAT) as number_float, " +
"CAST(4.56 as DOUBLE) as number_double, " +
"4.56BD as decimal, " +
"9.9999999999999999999999999999999999999BD as big_decimal, " +
Expand All @@ -164,7 +171,7 @@ public override SampleDataBuilder GetSampleDataBuilder()
[
new("id", typeof(long), typeof(Int64Type), 1L),
new("int", typeof(int), typeof(Int32Type), 2),
new("number_float", typeof(double), typeof(DoubleType), 1.23d),
new("number_float", floatNetType, floatArrowType, floatValue),
new("number_double", typeof(double), typeof(DoubleType), 4.56d),
new("decimal", typeof(SqlDecimal), typeof(Decimal128Type), SqlDecimal.Parse("4.56")),
new("big_decimal", typeof(SqlDecimal), typeof(Decimal128Type), SqlDecimal.Parse("9.9999999999999999999999999999999999999")),
Expand Down Expand Up @@ -200,13 +207,11 @@ public override SampleDataBuilder GetSampleDataBuilder()
"MAP(CAST('EMPTY' as STRING), CAST(NULL as INTEGER)) as map_null, " +
"ARRAY(NULL,NULL,NULL) as numbers_null, " +
"STRUCT(CAST(NULL as STRING), CAST(NULL as INTEGER)) as person_null",
//"CAST(NULL as STRUCT<field: STRING>) as struct, " +
//"STRUCT(CAST(NULL as STRING) as name, CAST(NULL as BIGINT) as age) as person",
ExpectedValues =
[
new("id", typeof(long), typeof(Int64Type), null),
new("int", typeof(int), typeof(Int32Type), null),
new("number_float", typeof(double), typeof(DoubleType), null),
new("number_float", floatNetType, floatArrowType, null),
new("number_double", typeof(double), typeof(DoubleType), null),
new("decimal", typeof(SqlDecimal), typeof(Decimal128Type), null),
new("is_active", typeof(bool), typeof(BooleanType), null),
Expand Down
Loading