Skip to content

Commit

Permalink
Task 574 - Treat DateTime type as String (for now) (Azure#27)
Browse files Browse the repository at this point in the history
* Task 574 - Treat DateTime type as String (for now)
  • Loading branch information
eladiw authored Aug 15, 2019
1 parent b83fa9b commit e1af3e9
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void dynamicallyTypedPrimitiveCollectionsDoNotAllRoundtripCorrectly() {
// Creating the document to be indexed
HashMap<String, Object> document = new HashMap<String, Object>();
document.put("Key", docKey);
document.put("Dates", new Object[]{});
document.put("Dates", new Object[]{"2019-08-13T14:30:00Z"});
document.put("Doubles", new Double[]{0.0, 5.8, POSITIVE_INFINITY, NEGATIVE_INFINITY, NaN});
document.put("Bools", new boolean[]{true, false});
document.put("Longs", new Long[]{9999999999999999L, 832372345832523L});
Expand All @@ -59,9 +59,14 @@ public void dynamicallyTypedPrimitiveCollectionsDoNotAllRoundtripCorrectly() {
expectedDocument.put("Longs", Arrays.asList(9999999999999999L, 832372345832523L));
expectedDocument.put("Strings", Arrays.asList("hello", "bye"));
expectedDocument.put("Ints", Arrays.asList(1, 2, 3, 4, -13, 5, 0));
// Todo: fix below 2 items

// Todo: The decision is to support DateTime as string until we support user supplying the concrete class
// in order to avoid trying to parse every string to a datetime (performance penalty)
expectedDocument.put("Dates", Arrays.asList("2019-08-13T14:30:00Z"));

// Todo: Support Geographic point
expectedDocument.put("Points", Arrays.asList());
expectedDocument.put("Dates", Arrays.asList());


// Index the document
indexDocument(client, document);
Expand All @@ -70,33 +75,6 @@ public void dynamicallyTypedPrimitiveCollectionsDoNotAllRoundtripCorrectly() {
getAndVerifyDoc(client, docKey, expectedDocument);
}

/**
* This test verifies that sometimes the converted type is not the right one and its by design
*/
//@Test
//public void getDynamicDocumentCannotAlwaysDetermineCorrectType() {
// Todo: Uncomment test, when task 574 is done
/*client.setIndexName(INDEX_NAME);
String docKey = "2";
// Creating the document to be indexed
// Set a String field to a valid datetime string
HashMap<String, Object> document = new HashMap<String, Object>();
document.put("Key", docKey);
document.put("Strings", Arrays.asList("2015-02-11T12:58:00Z"));
// This is the expected document when querying the document later
// Expect that the returned String field is actually converted to DateTime... which is wrong, but, by design.
HashMap<String, Object> expectedDocument = new HashMap<String, Object>();
expectedDocument.put("Key", docKey);
expectedDocument.put("Strings", Arrays.asList(DateTime.parse("2015-02-11T12:58:00Z")));
// Index the document
indexDocument(client, document);
getAndVerifyDoc(client, docKey, expectedDocument);*/
//}

@Test
public void emptyDynamicallyTypedPrimitiveCollectionsRoundtripAsObjectArrays() {
client.setIndexName(INDEX_NAME);
Expand Down Expand Up @@ -131,8 +109,37 @@ public void emptyDynamicallyTypedPrimitiveCollectionsRoundtripAsObjectArrays() {
getAndVerifyDoc(client, docKey, expectedDocument);
}

/**
* This test verifies our current assumption that uploaded DateTime, when requested
* returned as String. this test will be removed when the datetime type is handled
*/
@Test
public void dateTimeTypeIsReturnedAsString() {
final String indexName = "datetime-data-type-test-index";
client.setIndexName(indexName);
String docKey = "4";

// Creating the document to be indexed with a datetime field
HashMap<String, Object> document = new HashMap<String, Object>();
document.put("Key", docKey);
document.put("Date", "2019-08-13T14:30:00Z");

// This is the expected document when querying the document later
// we expect the converted type to remain string instead of DateTime
HashMap<String, Object> expectedDocument = new HashMap<String, Object>();
expectedDocument.put("Key", docKey);
expectedDocument.put("Date", "2019-08-13T14:30:00Z");

// Index the document
indexDocument(client, document);

// Get the indexed document
getAndVerifyDoc(client, docKey, expectedDocument);
}

/**
* Retrieve and verify the document
*
* @param client
* @param docKey
* @param expectedDocument
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "datetime-data-type-test-index",
"fields": [
{
"name": "Key",
"type": "Edm.String",
"key": true,
"retrievable": true
},
{
"name": "Date",
"type": "Edm.DateTimeOffset",
"retrievable": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"networkCallRecords" : [ {
"Method" : "POST",
"Uri" : "https://azs-sdked49427225e2.search.windows.net/indexes('datetime-data-type-test-index')/docs/search.index?api-version=2019-05-06",
"Headers" : {
"Content-Type" : "application/json; charset=utf-8"
},
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "1ba557b9-403a-4e82-9ac5-f3ce79180ffc",
"StatusCode" : "200",
"Date" : "Tue, 13 Aug 2019 11:46:38 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"elapsed-time" : "118",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "250",
"Body" : "{\"@odata.context\":\"https://azs-sdked49427225e2.search.windows.net/indexes('datetime-data-type-test-index')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.IndexResult)\",\"value\":[{\"key\":\"4\",\"status\":true,\"errorMessage\":null,\"statusCode\":201}]}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal"
}
}, {
"Method" : "GET",
"Uri" : "https://azs-sdked49427225e2.search.windows.net/indexes('datetime-data-type-test-index')/docs('4')?api-version=2019-05-06",
"Headers" : { },
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "e3312fa4-71b9-4559-9954-0b88f9b146b0",
"StatusCode" : "200",
"Date" : "Tue, 13 Aug 2019 11:46:38 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"elapsed-time" : "10",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "174",
"Body" : "{\"@odata.context\":\"https://azs-sdked49427225e2.search.windows.net/indexes('datetime-data-type-test-index')/$metadata#docs(*)/$entity\",\"Key\":\"4\",\"Date\":\"2019-08-13T14:30:00Z\"}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal"
}
} ],
"variables" : [ ]
}
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
{
"networkCallRecords" : [ {
"Method" : "POST",
"Uri" : "https://azs-sdk059236797c0f.search.windows.net/indexes('data-types-tests-index')/docs/search.index?api-version=2019-05-06",
"Uri" : "https://azs-sdkbfd0049547d8.search.windows.net/indexes('data-types-tests-index')/docs/search.index?api-version=2019-05-06",
"Headers" : {
"Content-Type" : "application/json; charset=utf-8"
},
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "83aa9506-1df6-4b35-b0de-fe7d9a6efe7b",
"request-id" : "189aa025-1da1-4950-8f36-c22c841ed655",
"StatusCode" : "200",
"Date" : "Mon, 12 Aug 2019 11:54:58 GMT",
"Date" : "Tue, 13 Aug 2019 11:51:22 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"elapsed-time" : "297",
"elapsed-time" : "125",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "227",
"Body" : "{\"@odata.context\":\"https://azs-sdk059236797c0f.search.windows.net/indexes('data-types-tests-index')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.IndexResult)\",\"value\":[{\"key\":\"1\",\"status\":true,\"errorMessage\":null,\"statusCode\":201}]}",
"Content-Length" : "243",
"Body" : "{\"@odata.context\":\"https://azs-sdkbfd0049547d8.search.windows.net/indexes('data-types-tests-index')/$metadata#Collection(Microsoft.Azure.Search.V2019_05_06.IndexResult)\",\"value\":[{\"key\":\"1\",\"status\":true,\"errorMessage\":null,\"statusCode\":201}]}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal"
}
}, {
"Method" : "GET",
"Uri" : "https://azs-sdk059236797c0f.search.windows.net/indexes('data-types-tests-index')/docs('1')?api-version=2019-05-06",
"Uri" : "https://azs-sdkbfd0049547d8.search.windows.net/indexes('data-types-tests-index')/docs('1')?api-version=2019-05-06",
"Headers" : { },
"Response" : {
"Pragma" : "no-cache",
"retry-after" : "0",
"request-id" : "ba5967c5-3390-4548-ad0d-21a27061e2af",
"request-id" : "1e9b6eb5-ff9d-4f06-bbc9-5b9aaaaa3b86",
"StatusCode" : "200",
"Date" : "Mon, 12 Aug 2019 11:54:58 GMT",
"Date" : "Tue, 13 Aug 2019 11:51:22 GMT",
"Strict-Transport-Security" : "max-age=15724800; includeSubDomains",
"Cache-Control" : "no-cache",
"elapsed-time" : "57",
"elapsed-time" : "15",
"OData-Version" : "4.0",
"Expires" : "-1",
"Content-Length" : "298",
"Body" : "{\"@odata.context\":\"https://azs-sdk059236797c0f.search.windows.net/indexes('data-types-tests-index')/$metadata#docs(*)/$entity\",\"Key\":\"1\",\"Bools\":[true,false],\"Dates\":[],\"Doubles\":[0.0,5.8,\"INF\",\"-INF\",\"NaN\"],\"Points\":[],\"Ints\":[1,2,3,4,-13,5,0],\"Longs\":[9999999999999999,832372345832523],\"Strings\":[\"hello\",\"bye\"]}",
"Content-Length" : "336",
"Body" : "{\"@odata.context\":\"https://azs-sdkbfd0049547d8.search.windows.net/indexes('data-types-tests-index')/$metadata#docs(*)/$entity\",\"Key\":\"1\",\"Bools\":[true,false],\"Dates\":[\"2019-08-13T14:30:00Z\"],\"Doubles\":[0.0,5.8,\"INF\",\"-INF\",\"NaN\"],\"Points\":[],\"Ints\":[1,2,3,4,-13,5,0],\"Longs\":[9999999999999999,832372345832523],\"Strings\":[\"hello\",\"bye\"]}",
"Preference-Applied" : "odata.include-annotations=\"*\"",
"Content-Type" : "application/json; odata.metadata=minimal"
}
Expand Down

0 comments on commit e1af3e9

Please sign in to comment.