Skip to content

Commit 53717b4

Browse files
authored
Add 'Z' to the string format in Timestamp.ToString() to indicate UTC time. (#871)
1 parent 33299cf commit 53717b4

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

azure-pipelines.yml

+20-11
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,27 @@ variables:
1616
backwardCompatibleRelease: '1.0.0'
1717
forwardCompatibleRelease: '1.0.0'
1818

19-
backwardCompatibleTestOptions_Windows_2_3: ""
20-
forwardCompatibleTestOptions_Windows_2_3: ""
21-
backwardCompatibleTestOptions_Linux_2_3: ""
22-
forwardCompatibleTestOptions_Linux_2_3: ""
23-
24-
backwardCompatibleTestOptions_Windows_2_4: ""
25-
forwardCompatibleTestOptions_Windows_2_4: ""
26-
backwardCompatibleTestOptions_Linux_2_4: ""
19+
# Filter UdfSimpleTypesTests.TestUdfWithReturnAsTimestampType and UdfSimpleTypesTests.TestUdfWithTimestampType
20+
# backward and forward compatibility tests due to bug with Timestamp.ToString(). This is not a breaking change.
21+
# Please see https://github.com/dotnet/spark/pull/871
22+
backwardCompatibleTestOptions_Windows_2_3: "--filter \
23+
(FullyQualifiedName!=Microsoft.Spark.E2ETest.UdfTests.UdfSimpleTypesTests.TestUdfWithReturnAsTimestampType)&\
24+
(FullyQualifiedName!=Microsoft.Spark.E2ETest.UdfTests.UdfSimpleTypesTests.TestUdfWithTimestampType)"
25+
forwardCompatibleTestOptions_Windows_2_3: $(backwardCompatibleTestOptions_Windows_2_3)
26+
backwardCompatibleTestOptions_Linux_2_3: $(backwardCompatibleTestOptions_Windows_2_3)
27+
forwardCompatibleTestOptions_Linux_2_3: $(backwardCompatibleTestOptions_Windows_2_3)
28+
29+
backwardCompatibleTestOptions_Windows_2_4: $(backwardCompatibleTestOptions_Windows_2_3)
30+
forwardCompatibleTestOptions_Windows_2_4: $(backwardCompatibleTestOptions_Windows_2_3)
31+
backwardCompatibleTestOptions_Linux_2_4: $(backwardCompatibleTestOptions_Windows_2_3)
2732
# Filter HyperspaceTests not due to functionality changes, but to incompatible tests running on Linux.
2833
# Please see https://github.com/dotnet/spark/pull/737 for the fix.
2934
forwardCompatibleTestOptions_Linux_2_4: "--filter \
3035
(FullyQualifiedName!=Microsoft.Spark.Extensions.Hyperspace.E2ETest.HyperspaceTests.TestExplainAPI)&\
3136
(FullyQualifiedName!=Microsoft.Spark.Extensions.Hyperspace.E2ETest.HyperspaceTests.TestIndexCreateAndDelete)&\
32-
(FullyQualifiedName!=Microsoft.Spark.Extensions.Hyperspace.E2ETest.HyperspaceTests.TestSignatures)"
37+
(FullyQualifiedName!=Microsoft.Spark.Extensions.Hyperspace.E2ETest.HyperspaceTests.TestSignatures&\
38+
(FullyQualifiedName!=Microsoft.Spark.E2ETest.UdfTests.UdfSimpleTypesTests.TestUdfWithReturnAsTimestampType)&\
39+
(FullyQualifiedName!=Microsoft.Spark.E2ETest.UdfTests.UdfSimpleTypesTests.TestUdfWithTimestampType)"
3340

3441
# Filter DataFrameTests.TestDataFrameGroupedMapUdf and DataFrameTests.TestGroupedMapUdf backwardCompatible
3542
# tests due to https://github.com/dotnet/spark/pull/711
@@ -38,8 +45,10 @@ variables:
3845
backwardCompatibleTestOptions_Windows_3_0: "--filter \
3946
(FullyQualifiedName!=Microsoft.Spark.E2ETest.IpcTests.DataFrameTests.TestDataFrameGroupedMapUdf)&\
4047
(FullyQualifiedName!=Microsoft.Spark.E2ETest.IpcTests.DataFrameTests.TestGroupedMapUdf)&\
41-
(FullyQualifiedName!=Microsoft.Spark.E2ETest.UdfTests.UdfSimpleTypesTests.TestUdfWithDuplicateTimestamps)"
42-
forwardCompatibleTestOptions_Windows_3_0: ""
48+
(FullyQualifiedName!=Microsoft.Spark.E2ETest.UdfTests.UdfSimpleTypesTests.TestUdfWithDuplicateTimestamps)&\
49+
(FullyQualifiedName!=Microsoft.Spark.E2ETest.UdfTests.UdfSimpleTypesTests.TestUdfWithReturnAsTimestampType)&\
50+
(FullyQualifiedName!=Microsoft.Spark.E2ETest.UdfTests.UdfSimpleTypesTests.TestUdfWithTimestampType)"
51+
forwardCompatibleTestOptions_Windows_3_0: $(backwardCompatibleTestOptions_Windows_2_3)
4352
backwardCompatibleTestOptions_Linux_3_0: $(backwardCompatibleTestOptions_Windows_3_0)
4453
forwardCompatibleTestOptions_Linux_3_0: $(forwardCompatibleTestOptions_Linux_2_4)
4554

src/csharp/Microsoft.Spark.E2ETest/UdfTests/UdfSimpleTypesTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ public void TestUdfWithTimestampType()
118118

119119
var expected = new string[]
120120
{
121-
"2020-01-01 00:00:00.000000",
122-
"2020-01-02 15:30:30.123456"
121+
"2020-01-01 00:00:00.000000Z",
122+
"2020-01-02 15:30:30.123456Z"
123123
};
124124
string[] rowsToArray = rows.Select(x => x[0].ToString()).ToArray();
125125
Assert.Equal(expected, rowsToArray);
@@ -193,8 +193,8 @@ public void TestUdfWithReturnAsTimestampType()
193193

194194
var expected = new string[]
195195
{
196-
"2020-01-04 15:30:30.123456",
197-
"2050-01-04 15:30:30.123456"
196+
"2020-01-04 15:30:30.123456Z",
197+
"2050-01-04 15:30:30.123456Z"
198198
};
199199
for (int i = 0; i < rows.Length; ++i)
200200
{

src/csharp/Microsoft.Spark.UnitTest/Sql/TimestampTests.cs

+11-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void TimestampTest()
2929
Assert.Equal(DateTimeKind.Utc, timestamp.ToDateTime().Kind);
3030

3131
// Validate ToString().
32-
Assert.Equal("2020-01-01 08:30:30.000123", timestamp.ToString());
32+
Assert.Equal("2020-01-01 08:30:30.000123Z", timestamp.ToString());
3333

3434
// Validate ToDateTime().
3535
Assert.Equal(testDate, timestamp.ToDateTime());
@@ -57,7 +57,7 @@ public void TimestampTest()
5757
Assert.Equal(DateTimeKind.Utc, timestamp.ToDateTime().Kind);
5858

5959
// Validate ToString().
60-
Assert.Equal("2020-01-02 15:30:30.123456", timestamp.ToString());
60+
Assert.Equal("2020-01-02 15:30:30.123456Z", timestamp.ToString());
6161

6262
// Validate ToDateTime().
6363
Assert.Equal(
@@ -71,5 +71,14 @@ public void TimestampTest()
7171
() => new Timestamp(2020, 1, 2, 15, 30, 30, 1234567));
7272
}
7373
}
74+
75+
[Fact]
76+
public void TestTimestampToString()
77+
{
78+
var dateTimeObj = new DateTime(2021, 01, 01);
79+
Assert.Equal(
80+
new Timestamp(DateTime.Parse(new Timestamp(dateTimeObj).ToString())),
81+
new Timestamp(dateTimeObj));
82+
}
7483
}
7584
}

src/csharp/Microsoft.Spark/Sql/Types/Timestamp.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public Timestamp(
9494
/// <summary>
9595
/// Readable string representation for this type.
9696
/// </summary>
97-
public override string ToString() => _dateTime.ToString("yyyy-MM-dd HH:mm:ss.ffffff");
97+
public override string ToString() => _dateTime.ToString("yyyy-MM-dd HH:mm:ss.ffffffZ");
9898

9999
/// <summary>
100100
/// Checks if the given object is same as the current object.

0 commit comments

Comments
 (0)