Repository: bahir
Updated Branches:
  refs/heads/master 0d9725d4c -> c7f158d86


http://git-wip-us.apache.org/repos/asf/bahir/blob/c7f158d8/sql-cloudant/src/test/resources/json-files/n_flightsegment.json
----------------------------------------------------------------------
diff --git a/sql-cloudant/src/test/resources/json-files/n_flightsegment.json 
b/sql-cloudant/src/test/resources/json-files/n_flightsegment.json
new file mode 100644
index 0000000..77aaa90
--- /dev/null
+++ b/sql-cloudant/src/test/resources/json-files/n_flightsegment.json
@@ -0,0 +1,2379 @@
+[
+       {
+               "miles": "4258",
+               "destPort": "BOM",
+               "_id": "AA0",
+               "originPort": "AMS"
+       },
+       {
+               "miles": "5737",
+               "destPort": "DEL",
+               "_id": "AA1",
+               "originPort": "AMS"
+       },
+       {
+               "miles": "6524",
+               "destPort": "SIN",
+               "_id": "AA10",
+               "originPort": "AMS"
+       },
+       {
+               "miles": "8205",
+               "destPort": "HKG",
+               "_id": "AA100",
+               "originPort": "GVA"
+       },
+       {
+               "miles": "457",
+               "destPort": "LHR",
+               "_id": "AA101",
+               "originPort": "GVA"
+       },
+       {
+               "miles": "3671",
+               "destPort": "YUL",
+               "_id": "AA102",
+               "originPort": "GVA"
+       },
+       {
+               "miles": "1493",
+               "destPort": "SVO",
+               "_id": "AA103",
+               "originPort": "GVA"
+       },
+       {
+               "miles": "3859",
+               "destPort": "JFK",
+               "_id": "AA104",
+               "originPort": "GVA"
+       },
+       {
+               "miles": "250",
+               "destPort": "CDG",
+               "_id": "AA105",
+               "originPort": "GVA"
+       },
+       {
+               "miles": "439",
+               "destPort": "FCO",
+               "_id": "AA106",
+               "originPort": "GVA"
+       },
+       {
+               "miles": "6519",
+               "destPort": "SIN",
+               "_id": "AA107",
+               "originPort": "GVA"
+       },
+       {
+               "miles": "12391",
+               "destPort": "SYD",
+               "_id": "AA108",
+               "originPort": "GVA"
+       },
+       {
+               "miles": "2434",
+               "destPort": "IKA",
+               "_id": "AA109",
+               "originPort": "GVA"
+       },
+       {
+               "miles": "13306",
+               "destPort": "SYD",
+               "_id": "AA11",
+               "originPort": "AMS"
+       },
+       {
+               "miles": "10029",
+               "destPort": "NRT",
+               "_id": "AA110",
+               "originPort": "GVA"
+       },
+       {
+               "miles": "2673",
+               "destPort": "BOM",
+               "_id": "AA111",
+               "originPort": "HKG"
+       },
+       {
+               "miles": "2345",
+               "destPort": "DEL",
+               "_id": "AA112",
+               "originPort": "HKG"
+       },
+       {
+               "miles": "8277",
+               "destPort": "FRA",
+               "_id": "AA113",
+               "originPort": "HKG"
+       },
+       {
+               "miles": "8252",
+               "destPort": "LHR",
+               "_id": "AA114",
+               "originPort": "HKG"
+       },
+       {
+               "miles": "10345",
+               "destPort": "YUL",
+               "_id": "AA115",
+               "originPort": "HKG"
+       },
+       {
+               "miles": "6063",
+               "destPort": "SVO",
+               "_id": "AA116",
+               "originPort": "HKG"
+       },
+       {
+               "miles": "10279",
+               "destPort": "JFK",
+               "_id": "AA117",
+               "originPort": "HKG"
+       },
+       {
+               "miles": "8493",
+               "destPort": "CDG",
+               "_id": "AA118",
+               "originPort": "HKG"
+       },
+       {
+               "miles": "7694",
+               "destPort": "FCO",
+               "_id": "AA119",
+               "originPort": "HKG"
+       },
+       {
+               "miles": "2527",
+               "destPort": "IKA",
+               "_id": "AA12",
+               "originPort": "AMS"
+       },
+       {
+               "miles": "1607",
+               "destPort": "SIN",
+               "_id": "AA120",
+               "originPort": "HKG"
+       },
+       {
+               "miles": "4586",
+               "destPort": "SYD",
+               "_id": "AA121",
+               "originPort": "HKG"
+       },
+       {
+               "miles": "3843",
+               "destPort": "IKA",
+               "_id": "AA122",
+               "originPort": "HKG"
+       },
+       {
+               "miles": "1788",
+               "destPort": "NRT",
+               "_id": "AA123",
+               "originPort": "HKG"
+       },
+       {
+               "miles": "2992",
+               "destPort": "BOM",
+               "_id": "AA124",
+               "originPort": "IST"
+       },
+       {
+               "miles": "4202",
+               "destPort": "DEL",
+               "_id": "AA125",
+               "originPort": "IST"
+       },
+       {
+               "miles": "1185",
+               "destPort": "FRA",
+               "_id": "AA126",
+               "originPort": "IST"
+       },
+       {
+               "miles": "7016",
+               "destPort": "HKG",
+               "_id": "AA127",
+               "originPort": "IST"
+       },
+       {
+               "miles": "1554",
+               "destPort": "LHR",
+               "_id": "AA128",
+               "originPort": "IST"
+       },
+       {
+               "miles": "5757",
+               "destPort": "YUL",
+               "_id": "AA129",
+               "originPort": "IST"
+       },
+       {
+               "miles": "9522",
+               "destPort": "NRT",
+               "_id": "AA13",
+               "originPort": "AMS"
+       },
+       {
+               "miles": "1093",
+               "destPort": "SVO",
+               "_id": "AA130",
+               "originPort": "IST"
+       },
+       {
+               "miles": "6010",
+               "destPort": "JFK",
+               "_id": "AA131",
+               "originPort": "IST"
+       },
+       {
+               "miles": "1394",
+               "destPort": "CDG",
+               "_id": "AA132",
+               "originPort": "IST"
+       },
+       {
+               "miles": "852",
+               "destPort": "FCO",
+               "_id": "AA133",
+               "originPort": "IST"
+       },
+       {
+               "miles": "5379",
+               "destPort": "SIN",
+               "_id": "AA134",
+               "originPort": "IST"
+       },
+       {
+               "miles": "11772",
+               "destPort": "SYD",
+               "_id": "AA135",
+               "originPort": "IST"
+       },
+       {
+               "miles": "1270",
+               "destPort": "IKA",
+               "_id": "AA136",
+               "originPort": "IST"
+       },
+       {
+               "miles": "9162",
+               "destPort": "NRT",
+               "_id": "AA137",
+               "originPort": "IST"
+       },
+       {
+               "miles": "544",
+               "destPort": "BOM",
+               "_id": "AA138",
+               "originPort": "KHI"
+       },
+       {
+               "miles": "655",
+               "destPort": "DEL",
+               "_id": "AA139",
+               "originPort": "KHI"
+       },
+       {
+               "miles": "7662",
+               "destPort": "BOM",
+               "_id": "AA14",
+               "originPort": "AKL"
+       },
+       {
+               "miles": "3539",
+               "destPort": "FRA",
+               "_id": "AA140",
+               "originPort": "KHI"
+       },
+       {
+               "miles": "3596",
+               "destPort": "HKG",
+               "_id": "AA141",
+               "originPort": "KHI"
+       },
+       {
+               "miles": "5276",
+               "destPort": "LHR",
+               "_id": "AA142",
+               "originPort": "KHI"
+       },
+       {
+               "miles": "8888",
+               "destPort": "YUL",
+               "_id": "AA143",
+               "originPort": "KHI"
+       },
+       {
+               "miles": "2608",
+               "destPort": "SVO",
+               "_id": "AA144",
+               "originPort": "KHI"
+       },
+       {
+               "miles": "9104",
+               "destPort": "JFK",
+               "_id": "AA145",
+               "originPort": "KHI"
+       },
+       {
+               "miles": "3810",
+               "destPort": "CDG",
+               "_id": "AA146",
+               "originPort": "KHI"
+       },
+       {
+               "miles": "3307",
+               "destPort": "FCO",
+               "_id": "AA147",
+               "originPort": "KHI"
+       },
+       {
+               "miles": "2943",
+               "destPort": "SIN",
+               "_id": "AA148",
+               "originPort": "KHI"
+       },
+       {
+               "miles": "8269",
+               "destPort": "SYD",
+               "_id": "AA149",
+               "originPort": "KHI"
+       },
+       {
+               "miles": "9406",
+               "destPort": "DEL",
+               "_id": "AA15",
+               "originPort": "AKL"
+       },
+       {
+               "miles": "1199",
+               "destPort": "IKA",
+               "_id": "AA150",
+               "originPort": "KHI"
+       },
+       {
+               "miles": "5742",
+               "destPort": "NRT",
+               "_id": "AA151",
+               "originPort": "KHI"
+       },
+       {
+               "miles": "1714",
+               "destPort": "BOM",
+               "_id": "AA152",
+               "originPort": "KWI"
+       },
+       {
+               "miles": "1755",
+               "destPort": "DEL",
+               "_id": "AA153",
+               "originPort": "KWI"
+       },
+       {
+               "miles": "2499",
+               "destPort": "FRA",
+               "_id": "AA154",
+               "originPort": "KWI"
+       },
+       {
+               "miles": "4092",
+               "destPort": "HKG",
+               "_id": "AA155",
+               "originPort": "KWI"
+       },
+       {
+               "miles": "2903",
+               "destPort": "LHR",
+               "_id": "AA156",
+               "originPort": "KWI"
+       },
+       {
+               "miles": "6264",
+               "destPort": "YUL",
+               "_id": "AA157",
+               "originPort": "KWI"
+       },
+       {
+               "miles": "1918",
+               "destPort": "SVO",
+               "_id": "AA158",
+               "originPort": "KWI"
+       },
+       {
+               "miles": "6335",
+               "destPort": "JFK",
+               "_id": "AA159",
+               "originPort": "KWI"
+       },
+       {
+               "miles": "6883",
+               "destPort": "FRA",
+               "_id": "AA16",
+               "originPort": "AKL"
+       },
+       {
+               "miles": "2739",
+               "destPort": "CDG",
+               "_id": "AA160",
+               "originPort": "KWI"
+       },
+       {
+               "miles": "2168",
+               "destPort": "FCO",
+               "_id": "AA161",
+               "originPort": "KWI"
+       },
+       {
+               "miles": "2942",
+               "destPort": "SIN",
+               "_id": "AA162",
+               "originPort": "KWI"
+       },
+       {
+               "miles": "8007",
+               "destPort": "SYD",
+               "_id": "AA163",
+               "originPort": "KWI"
+       },
+       {
+               "miles": "1200",
+               "destPort": "IKA",
+               "_id": "AA164",
+               "originPort": "KWI"
+       },
+       {
+               "miles": "5168",
+               "destPort": "NRT",
+               "_id": "AA165",
+               "originPort": "KWI"
+       },
+       {
+               "miles": "5140",
+               "destPort": "BOM",
+               "_id": "AA166",
+               "originPort": "LOS"
+       },
+       {
+               "miles": "6015",
+               "destPort": "DEL",
+               "_id": "AA167",
+               "originPort": "LOS"
+       },
+       {
+               "miles": "3018",
+               "destPort": "FRA",
+               "_id": "AA168",
+               "originPort": "LOS"
+       },
+       {
+               "miles": "8930",
+               "destPort": "HKG",
+               "_id": "AA169",
+               "originPort": "LOS"
+       },
+       {
+               "miles": "6883",
+               "destPort": "HKG",
+               "_id": "AA17",
+               "originPort": "AKL"
+       },
+       {
+               "miles": "3098",
+               "destPort": "LHR",
+               "_id": "AA170",
+               "originPort": "LOS"
+       },
+       {
+               "miles": "6734",
+               "destPort": "YUL",
+               "_id": "AA171",
+               "originPort": "LOS"
+       },
+       {
+               "miles": "4806",
+               "destPort": "SVO",
+               "_id": "AA172",
+               "originPort": "LOS"
+       },
+       {
+               "miles": "6508",
+               "destPort": "JFK",
+               "_id": "AA173",
+               "originPort": "LOS"
+       },
+       {
+               "miles": "2922",
+               "destPort": "CDG",
+               "_id": "AA174",
+               "originPort": "LOS"
+       },
+       {
+               "miles": "2497",
+               "destPort": "FCO",
+               "_id": "AA175",
+               "originPort": "LOS"
+       },
+       {
+               "miles": "7428",
+               "destPort": "SIN",
+               "_id": "AA176",
+               "originPort": "LOS"
+       },
+       {
+               "miles": "11898",
+               "destPort": "SYD",
+               "_id": "AA177",
+               "originPort": "LOS"
+       },
+       {
+               "miles": "3659",
+               "destPort": "IKA",
+               "_id": "AA178",
+               "originPort": "LOS"
+       },
+       {
+               "miles": "11076",
+               "destPort": "NRT",
+               "_id": "AA179",
+               "originPort": "LOS"
+       },
+       {
+               "miles": "14202",
+               "destPort": "LHR",
+               "_id": "AA18",
+               "originPort": "AKL"
+       },
+       {
+               "miles": "4477",
+               "destPort": "BOM",
+               "_id": "AA180",
+               "originPort": "LHR"
+       },
+       {
+               "miles": "5907",
+               "destPort": "DEL",
+               "_id": "AA181",
+               "originPort": "LHR"
+       },
+       {
+               "miles": "400",
+               "destPort": "FRA",
+               "_id": "AA182",
+               "originPort": "LHR"
+       },
+       {
+               "miles": "8252",
+               "destPort": "HKG",
+               "_id": "AA183",
+               "originPort": "LHR"
+       },
+       {
+               "miles": "3251",
+               "destPort": "YUL",
+               "_id": "AA184",
+               "originPort": "LHR"
+       },
+       {
+               "miles": "1557",
+               "destPort": "SVO",
+               "_id": "AA185",
+               "originPort": "LHR"
+       },
+       {
+               "miles": "3456",
+               "destPort": "JFK",
+               "_id": "AA186",
+               "originPort": "LHR"
+       },
+       {
+               "miles": "209",
+               "destPort": "CDG",
+               "_id": "AA187",
+               "originPort": "LHR"
+       },
+       {
+               "miles": "892",
+               "destPort": "FCO",
+               "_id": "AA188",
+               "originPort": "LHR"
+       },
+       {
+               "miles": "6754",
+               "destPort": "SIN",
+               "_id": "AA189",
+               "originPort": "LHR"
+       },
+       {
+               "miles": "10968",
+               "destPort": "YUL",
+               "_id": "AA19",
+               "originPort": "AKL"
+       },
+       {
+               "miles": "13477",
+               "destPort": "SYD",
+               "_id": "AA190",
+               "originPort": "LHR"
+       },
+       {
+               "miles": "2738",
+               "destPort": "IKA",
+               "_id": "AA191",
+               "originPort": "LHR"
+       },
+       {
+               "miles": "9536",
+               "destPort": "NRT",
+               "_id": "AA192",
+               "originPort": "LHR"
+       },
+       {
+               "miles": "3189",
+               "destPort": "BOM",
+               "_id": "AA193",
+               "originPort": "MNL"
+       },
+       {
+               "miles": "3656",
+               "destPort": "DEL",
+               "_id": "AA194",
+               "originPort": "MNL"
+       },
+       {
+               "miles": "6394",
+               "destPort": "FRA",
+               "_id": "AA195",
+               "originPort": "MNL"
+       },
+       {
+               "miles": "702",
+               "destPort": "HKG",
+               "_id": "AA196",
+               "originPort": "MNL"
+       },
+       {
+               "miles": "9564",
+               "destPort": "LHR",
+               "_id": "AA197",
+               "originPort": "MNL"
+       },
+       {
+               "miles": "2332",
+               "destPort": "YUL",
+               "_id": "AA198",
+               "originPort": "MNL"
+       },
+       {
+               "miles": "6906",
+               "destPort": "SVO",
+               "_id": "AA199",
+               "originPort": "MNL"
+       },
+       {
+               "miles": "228",
+               "destPort": "FRA",
+               "_id": "AA2",
+               "originPort": "AMS"
+       },
+       {
+               "miles": "14622",
+               "destPort": "SVO",
+               "_id": "AA20",
+               "originPort": "AKL"
+       },
+       {
+               "miles": "10368",
+               "destPort": "JFK",
+               "_id": "AA200",
+               "originPort": "MNL"
+       },
+       {
+               "miles": "9336",
+               "destPort": "CDG",
+               "_id": "AA201",
+               "originPort": "MNL"
+       },
+       {
+               "miles": "8536",
+               "destPort": "FCO",
+               "_id": "AA202",
+               "originPort": "MNL"
+       },
+       {
+               "miles": "1481",
+               "destPort": "SIN",
+               "_id": "AA203",
+               "originPort": "MNL"
+       },
+       {
+               "miles": "3892",
+               "destPort": "SYD",
+               "_id": "AA204",
+               "originPort": "MNL"
+       },
+       {
+               "miles": "4503",
+               "destPort": "IKA",
+               "_id": "AA205",
+               "originPort": "MNL"
+       },
+       {
+               "miles": "1862",
+               "destPort": "NRT",
+               "_id": "AA206",
+               "originPort": "MNL"
+       },
+       {
+               "miles": "10206",
+               "destPort": "BOM",
+               "_id": "AA207",
+               "originPort": "MEX"
+       },
+       {
+               "miles": "12054",
+               "destPort": "DEL",
+               "_id": "AA208",
+               "originPort": "MEX"
+       },
+       {
+               "miles": "7124",
+               "destPort": "FRA",
+               "_id": "AA209",
+               "originPort": "MEX"
+       },
+       {
+               "miles": "10730",
+               "destPort": "JFK",
+               "_id": "AA21",
+               "originPort": "AKL"
+       },
+       {
+               "miles": "10726",
+               "destPort": "HKG",
+               "_id": "AA210",
+               "originPort": "MEX"
+       },
+       {
+               "miles": "6649",
+               "destPort": "LHR",
+               "_id": "AA211",
+               "originPort": "MEX"
+       },
+       {
+               "miles": "2306",
+               "destPort": "YUL",
+               "_id": "AA212",
+               "originPort": "MEX"
+       },
+       {
+               "miles": "8058",
+               "destPort": "SVO",
+               "_id": "AA213",
+               "originPort": "MEX"
+       },
+       {
+               "miles": "2086",
+               "destPort": "JFK",
+               "_id": "AA214",
+               "originPort": "MEX"
+       },
+       {
+               "miles": "6856",
+               "destPort": "CDG",
+               "_id": "AA215",
+               "originPort": "MEX"
+       },
+       {
+               "miles": "7639",
+               "destPort": "FCO",
+               "_id": "AA216",
+               "originPort": "MEX"
+       },
+       {
+               "miles": "12638",
+               "destPort": "SIN",
+               "_id": "AA217",
+               "originPort": "MEX"
+       },
+       {
+               "miles": "9457",
+               "destPort": "SYD",
+               "_id": "AA218",
+               "originPort": "MEX"
+       },
+       {
+               "miles": "8487",
+               "destPort": "IKA",
+               "_id": "AA219",
+               "originPort": "MEX"
+       },
+       {
+               "miles": "14452",
+               "destPort": "CDG",
+               "_id": "AA22",
+               "originPort": "AKL"
+       },
+       {
+               "miles": "8588",
+               "destPort": "NRT",
+               "_id": "AA220",
+               "originPort": "MEX"
+       },
+       {
+               "miles": "7942",
+               "destPort": "BOM",
+               "_id": "AA221",
+               "originPort": "YUL"
+       },
+       {
+               "miles": "3821",
+               "destPort": "DEL",
+               "_id": "AA222",
+               "originPort": "YUL"
+       },
+       {
+               "miles": "3640",
+               "destPort": "FRA",
+               "_id": "AA223",
+               "originPort": "YUL"
+       },
+       {
+               "miles": "10345",
+               "destPort": "HKG",
+               "_id": "AA224",
+               "originPort": "YUL"
+       },
+       {
+               "miles": "3251",
+               "destPort": "LHR",
+               "_id": "AA225",
+               "originPort": "YUL"
+       },
+       {
+               "miles": "5259",
+               "destPort": "SVO",
+               "_id": "AA226",
+               "originPort": "YUL"
+       },
+       {
+               "miles": "330",
+               "destPort": "JFK",
+               "_id": "AA227",
+               "originPort": "YUL"
+       },
+       {
+               "miles": "3433",
+               "destPort": "CDG",
+               "_id": "AA228",
+               "originPort": "YUL"
+       },
+       {
+               "miles": "4100",
+               "destPort": "FCO",
+               "_id": "AA229",
+               "originPort": "YUL"
+       },
+       {
+               "miles": "14061",
+               "destPort": "FCO",
+               "_id": "AA23",
+               "originPort": "AKL"
+       },
+       {
+               "miles": "9193",
+               "destPort": "SIN",
+               "_id": "AA230",
+               "originPort": "YUL"
+       },
+       {
+               "miles": "12045",
+               "destPort": "SYD",
+               "_id": "AA231",
+               "originPort": "YUL"
+       },
+       {
+               "miles": "6223",
+               "destPort": "IKA",
+               "_id": "AA232",
+               "originPort": "YUL"
+       },
+       {
+               "miles": "8199",
+               "destPort": "NRT",
+               "_id": "AA233",
+               "originPort": "YUL"
+       },
+       {
+               "miles": "3136",
+               "destPort": "BOM",
+               "_id": "AA234",
+               "originPort": "SVO"
+       },
+       {
+               "miles": "2708",
+               "destPort": "DEL",
+               "_id": "AA235",
+               "originPort": "SVO"
+       },
+       {
+               "miles": "1253",
+               "destPort": "FRA",
+               "_id": "AA236",
+               "originPort": "SVO"
+       },
+       {
+               "miles": "6063",
+               "destPort": "HKG",
+               "_id": "AA237",
+               "originPort": "SVO"
+       },
+       {
+               "miles": "1557",
+               "destPort": "LHR",
+               "_id": "AA238",
+               "originPort": "SVO"
+       },
+       {
+               "miles": "5259",
+               "destPort": "YUL",
+               "_id": "AA239",
+               "originPort": "SVO"
+       },
+       {
+               "miles": "5230",
+               "destPort": "SIN",
+               "_id": "AA24",
+               "originPort": "AKL"
+       },
+       {
+               "miles": "5620",
+               "destPort": "JFK",
+               "_id": "AA240",
+               "originPort": "SVO"
+       },
+       {
+               "miles": "1533",
+               "destPort": "CDG",
+               "_id": "AA241",
+               "originPort": "SVO"
+       },
+       {
+               "miles": "1476",
+               "destPort": "FCO",
+               "_id": "AA242",
+               "originPort": "SVO"
+       },
+       {
+               "miles": "5242",
+               "destPort": "SIN",
+               "_id": "AA243",
+               "originPort": "SVO"
+       },
+       {
+               "miles": "11044",
+               "destPort": "SYD",
+               "_id": "AA244",
+               "originPort": "SVO"
+       },
+       {
+               "miles": "1526",
+               "destPort": "IKA",
+               "_id": "AA245",
+               "originPort": "SVO"
+       },
+       {
+               "miles": "4667",
+               "destPort": "NRT",
+               "_id": "AA246",
+               "originPort": "SVO"
+       },
+       {
+               "miles": "2817",
+               "destPort": "BOM",
+               "_id": "AA247",
+               "originPort": "NBO"
+       },
+       {
+               "miles": "3364",
+               "destPort": "DEL",
+               "_id": "AA248",
+               "originPort": "NBO"
+       },
+       {
+               "miles": "3925",
+               "destPort": "FRA",
+               "_id": "AA249",
+               "originPort": "NBO"
+       },
+       {
+               "miles": "1343",
+               "destPort": "SYD",
+               "_id": "AA25",
+               "originPort": "AKL"
+       },
+       {
+               "miles": "5347",
+               "destPort": "HKG",
+               "_id": "AA250",
+               "originPort": "NBO"
+       },
+       {
+               "miles": "4247",
+               "destPort": "LHR",
+               "_id": "AA251",
+               "originPort": "NBO"
+       },
+       {
+               "miles": "7271",
+               "destPort": "YUL",
+               "_id": "AA252",
+               "originPort": "NBO"
+       },
+       {
+               "miles": "3955",
+               "destPort": "SVO",
+               "_id": "AA253",
+               "originPort": "NBO"
+       },
+       {
+               "miles": "7349",
+               "destPort": "JFK",
+               "_id": "AA254",
+               "originPort": "NBO"
+       },
+       {
+               "miles": "4027",
+               "destPort": "CDG",
+               "_id": "AA255",
+               "originPort": "NBO"
+       },
+       {
+               "miles": "3353",
+               "destPort": "FCO",
+               "_id": "AA256",
+               "originPort": "NBO"
+       },
+       {
+               "miles": "4628",
+               "destPort": "SIN",
+               "_id": "AA257",
+               "originPort": "NBO"
+       },
+       {
+               "miles": "7536",
+               "destPort": "SYD",
+               "_id": "AA258",
+               "originPort": "NBO"
+       },
+       {
+               "miles": "2718",
+               "destPort": "IKA",
+               "_id": "AA259",
+               "originPort": "NBO"
+       },
+       {
+               "miles": "9338",
+               "destPort": "IKA",
+               "_id": "AA26",
+               "originPort": "AKL"
+       },
+       {
+               "miles": "7019",
+               "destPort": "NRT",
+               "_id": "AA260",
+               "originPort": "NBO"
+       },
+       {
+               "miles": "7718",
+               "destPort": "BOM",
+               "_id": "AA261",
+               "originPort": "JFK"
+       },
+       {
+               "miles": "9550",
+               "destPort": "DEL",
+               "_id": "AA262",
+               "originPort": "JFK"
+       },
+       {
+               "miles": "3851",
+               "destPort": "FRA",
+               "_id": "AA263",
+               "originPort": "JFK"
+       },
+       {
+               "miles": "10279",
+               "destPort": "HKG",
+               "_id": "AA264",
+               "originPort": "JFK"
+       },
+       {
+               "miles": "3456",
+               "destPort": "LHR",
+               "_id": "AA265",
+               "originPort": "JFK"
+       },
+       {
+               "miles": "330",
+               "destPort": "YUL",
+               "_id": "AA266",
+               "originPort": "JFK"
+       },
+       {
+               "miles": "5620",
+               "destPort": "SVO",
+               "_id": "AA267",
+               "originPort": "JFK"
+       },
+       {
+               "miles": "3628",
+               "destPort": "CDG",
+               "_id": "AA268",
+               "originPort": "JFK"
+       },
+       {
+               "miles": "4280",
+               "destPort": "FCO",
+               "_id": "AA269",
+               "originPort": "JFK"
+       },
+       {
+               "miles": "8275",
+               "destPort": "NRT",
+               "_id": "AA27",
+               "originPort": "AKL"
+       },
+       {
+               "miles": "9525",
+               "destPort": "SIN",
+               "_id": "AA270",
+               "originPort": "JFK"
+       },
+       {
+               "miles": "12052",
+               "destPort": "SYD",
+               "_id": "AA271",
+               "originPort": "JFK"
+       },
+       {
+               "miles": "6113",
+               "destPort": "IKA",
+               "_id": "AA272",
+               "originPort": "JFK"
+       },
+       {
+               "miles": "8133",
+               "destPort": "NRT",
+               "_id": "AA273",
+               "originPort": "JFK"
+       },
+       {
+               "miles": "4349",
+               "destPort": "BOM",
+               "_id": "AA274",
+               "originPort": "CDG"
+       },
+       {
+               "miles": "5679",
+               "destPort": "DEL",
+               "_id": "AA275",
+               "originPort": "CDG"
+       },
+       {
+               "miles": "269",
+               "destPort": "FRA",
+               "_id": "AA276",
+               "originPort": "CDG"
+       },
+       {
+               "miles": "8493",
+               "destPort": "HKG",
+               "_id": "AA277",
+               "originPort": "CDG"
+       },
+       {
+               "miles": "209",
+               "destPort": "LHR",
+               "_id": "AA278",
+               "originPort": "CDG"
+       },
+       {
+               "miles": "3433",
+               "destPort": "YUL",
+               "_id": "AA279",
+               "originPort": "CDG"
+       },
+       {
+               "miles": "1871",
+               "destPort": "BOM",
+               "_id": "AA28",
+               "originPort": "BKK"
+       },
+       {
+               "miles": "1533",
+               "destPort": "SVO",
+               "_id": "AA280",
+               "originPort": "CDG"
+       },
+       {
+               "miles": "3628",
+               "destPort": "JFK",
+               "_id": "AA281",
+               "originPort": "CDG"
+       },
+       {
+               "miles": "688",
+               "destPort": "FCO",
+               "_id": "AA282",
+               "originPort": "CDG"
+       },
+       {
+               "miles": "6667",
+               "destPort": "SIN",
+               "_id": "AA283",
+               "originPort": "CDG"
+       },
+       {
+               "miles": "13249",
+               "destPort": "SYD",
+               "_id": "AA284",
+               "originPort": "CDG"
+       },
+       {
+               "miles": "2610",
+               "destPort": "IKA",
+               "_id": "AA285",
+               "originPort": "CDG"
+       },
+       {
+               "miles": "9771",
+               "destPort": "NRT",
+               "_id": "AA286",
+               "originPort": "CDG"
+       },
+       {
+               "miles": "9334",
+               "destPort": "BOM",
+               "_id": "AA287",
+               "originPort": "PRG"
+       },
+       {
+               "miles": "3549",
+               "destPort": "DEL",
+               "_id": "AA288",
+               "originPort": "PRG"
+       },
+       {
+               "miles": "253",
+               "destPort": "FRA",
+               "_id": "AA289",
+               "originPort": "PRG"
+       },
+       {
+               "miles": "1815",
+               "destPort": "DEL",
+               "_id": "AA29",
+               "originPort": "BKK"
+       },
+       {
+               "miles": "5460",
+               "destPort": "HKG",
+               "_id": "AA290",
+               "originPort": "PRG"
+       },
+       {
+               "miles": "649",
+               "destPort": "LHR",
+               "_id": "AA291",
+               "originPort": "PRG"
+       },
+       {
+               "miles": "3852",
+               "destPort": "YUL",
+               "_id": "AA292",
+               "originPort": "PRG"
+       },
+       {
+               "miles": "1036",
+               "destPort": "SVO",
+               "_id": "AA293",
+               "originPort": "PRG"
+       },
+       {
+               "miles": "4066",
+               "destPort": "JFK",
+               "_id": "AA294",
+               "originPort": "PRG"
+       },
+       {
+               "miles": "542",
+               "destPort": "CDG",
+               "_id": "AA295",
+               "originPort": "PRG"
+       },
+       {
+               "miles": "581",
+               "destPort": "FCO",
+               "_id": "AA296",
+               "originPort": "PRG"
+       },
+       {
+               "miles": "6126",
+               "destPort": "SIN",
+               "_id": "AA297",
+               "originPort": "PRG"
+       },
+       {
+               "miles": "9997",
+               "destPort": "SYD",
+               "_id": "AA298",
+               "originPort": "PRG"
+       },
+       {
+               "miles": "2093",
+               "destPort": "IKA",
+               "_id": "AA299",
+               "originPort": "PRG"
+       },
+       {
+               "miles": "8551",
+               "destPort": "HKG",
+               "_id": "AA3",
+               "originPort": "AMS"
+       },
+       {
+               "miles": "5575",
+               "destPort": "FRA",
+               "_id": "AA30",
+               "originPort": "BKK"
+       },
+       {
+               "miles": "8531",
+               "destPort": "NRT",
+               "_id": "AA300",
+               "originPort": "PRG"
+       },
+       {
+               "miles": "9547",
+               "destPort": "BOM",
+               "_id": "AA301",
+               "originPort": "GIG"
+       },
+       {
+               "miles": "11263",
+               "destPort": "DEL",
+               "_id": "AA302",
+               "originPort": "GIG"
+       },
+       {
+               "miles": "9775",
+               "destPort": "FRA",
+               "_id": "AA303",
+               "originPort": "GIG"
+       },
+       {
+               "miles": "13429",
+               "destPort": "HKG",
+               "_id": "AA304",
+               "originPort": "GIG"
+       },
+       {
+               "miles": "6914",
+               "destPort": "LHR",
+               "_id": "AA305",
+               "originPort": "GIG"
+       },
+       {
+               "miles": "6175",
+               "destPort": "YUL",
+               "_id": "AA306",
+               "originPort": "GIG"
+       },
+       {
+               "miles": "8606",
+               "destPort": "SVO",
+               "_id": "AA307",
+               "originPort": "GIG"
+       },
+       {
+               "miles": "4816",
+               "destPort": "JFK",
+               "_id": "AA308",
+               "originPort": "GIG"
+       },
+       {
+               "miles": "5697",
+               "destPort": "CDG",
+               "_id": "AA309",
+               "originPort": "GIG"
+       },
+       {
+               "miles": "1065",
+               "destPort": "HKG",
+               "_id": "AA31",
+               "originPort": "BKK"
+       },
+       {
+               "miles": "5707",
+               "destPort": "FCO",
+               "_id": "AA310",
+               "originPort": "GIG"
+       },
+       {
+               "miles": "9775",
+               "destPort": "SIN",
+               "_id": "AA311",
+               "originPort": "GIG"
+       },
+       {
+               "miles": "12741",
+               "destPort": "SYD",
+               "_id": "AA312",
+               "originPort": "GIG"
+       },
+       {
+               "miles": "7828",
+               "destPort": "IKA",
+               "_id": "AA313",
+               "originPort": "GIG"
+       },
+       {
+               "miles": "13512",
+               "destPort": "NRT",
+               "_id": "AA314",
+               "originPort": "GIG"
+       },
+       {
+               "miles": "3840",
+               "destPort": "BOM",
+               "_id": "AA315",
+               "originPort": "FCO"
+       },
+       {
+               "miles": "3679",
+               "destPort": "DEL",
+               "_id": "AA316",
+               "originPort": "FCO"
+       },
+       {
+               "miles": "6238",
+               "destPort": "FRA",
+               "_id": "AA317",
+               "originPort": "FCO"
+       },
+       {
+               "miles": "7694",
+               "destPort": "HKG",
+               "_id": "AA318",
+               "originPort": "FCO"
+       },
+       {
+               "miles": "892",
+               "destPort": "LHR",
+               "_id": "AA319",
+               "originPort": "FCO"
+       },
+       {
+               "miles": "8038",
+               "destPort": "LHR",
+               "_id": "AA32",
+               "originPort": "BKK"
+       },
+       {
+               "miles": "4100",
+               "destPort": "YUL",
+               "_id": "AA320",
+               "originPort": "FCO"
+       },
+       {
+               "miles": "1476",
+               "destPort": "SVO",
+               "_id": "AA321",
+               "originPort": "FCO"
+       },
+       {
+               "miles": "4280",
+               "destPort": "JFK",
+               "_id": "AA322",
+               "originPort": "FCO"
+       },
+       {
+               "miles": "688",
+               "destPort": "CDG",
+               "_id": "AA323",
+               "originPort": "FCO"
+       },
+       {
+               "miles": "6238",
+               "destPort": "SIN",
+               "_id": "AA324",
+               "originPort": "FCO"
+       },
+       {
+               "miles": "12450",
+               "destPort": "SYD",
+               "_id": "AA325",
+               "originPort": "FCO"
+       },
+       {
+               "miles": "2121",
+               "destPort": "IKA",
+               "_id": "AA326",
+               "originPort": "FCO"
+       },
+       {
+               "miles": "9840",
+               "destPort": "NRT",
+               "_id": "AA327",
+               "originPort": "FCO"
+       },
+       {
+               "miles": "2432",
+               "destPort": "BOM",
+               "_id": "AA328",
+               "originPort": "SIN"
+       },
+       {
+               "miles": "2578",
+               "destPort": "DEL",
+               "_id": "AA329",
+               "originPort": "SIN"
+       },
+       {
+               "miles": "11618",
+               "destPort": "YUL",
+               "_id": "AA33",
+               "originPort": "BKK"
+       },
+       {
+               "miles": "6379",
+               "destPort": "FRA",
+               "_id": "AA330",
+               "originPort": "SIN"
+       },
+       {
+               "miles": "1605",
+               "destPort": "HKG",
+               "_id": "AA331",
+               "originPort": "SIN"
+       },
+       {
+               "miles": "6754",
+               "destPort": "LHR",
+               "_id": "AA332",
+               "originPort": "SIN"
+       },
+       {
+               "miles": "9193",
+               "destPort": "YUL",
+               "_id": "AA333",
+               "originPort": "SIN"
+       },
+       {
+               "miles": "5252",
+               "destPort": "SVO",
+               "_id": "AA334",
+               "originPort": "SIN"
+       },
+       {
+               "miles": "9525",
+               "destPort": "JFK",
+               "_id": "AA335",
+               "originPort": "SIN"
+       },
+       {
+               "miles": "6667",
+               "destPort": "CDG",
+               "_id": "AA336",
+               "originPort": "SIN"
+       },
+       {
+               "miles": "6238",
+               "destPort": "FCO",
+               "_id": "AA337",
+               "originPort": "SIN"
+       },
+       {
+               "miles": "3912",
+               "destPort": "SYD",
+               "_id": "AA338",
+               "originPort": "SIN"
+       },
+       {
+               "miles": "4110",
+               "destPort": "IKA",
+               "_id": "AA339",
+               "originPort": "SIN"
+       },
+       {
+               "miles": "4396",
+               "destPort": "SVO",
+               "_id": "AA34",
+               "originPort": "BKK"
+       },
+       {
+               "miles": "3294",
+               "destPort": "NRT",
+               "_id": "AA340",
+               "originPort": "SIN"
+       },
+       {
+               "miles": "4842",
+               "destPort": "BOM",
+               "_id": "AA341",
+               "originPort": "ARN"
+       },
+       {
+               "miles": "6057",
+               "destPort": "DEL",
+               "_id": "AA342",
+               "originPort": "ARN"
+       },
+       {
+               "miles": "730",
+               "destPort": "FRA",
+               "_id": "AA343",
+               "originPort": "ARN"
+       },
+       {
+               "miles": "8871",
+               "destPort": "HKG",
+               "_id": "AA344",
+               "originPort": "ARN"
+       },
+       {
+               "miles": "908",
+               "destPort": "LHR",
+               "_id": "AA345",
+               "originPort": "ARN"
+       },
+       {
+               "miles": "4725",
+               "destPort": "YUL",
+               "_id": "AA346",
+               "originPort": "ARN"
+       },
+       {
+               "miles": "760",
+               "destPort": "SVO",
+               "_id": "AA347",
+               "originPort": "ARN"
+       },
+       {
+               "miles": "3917",
+               "destPort": "JFK",
+               "_id": "AA348",
+               "originPort": "ARN"
+       },
+       {
+               "miles": "963",
+               "destPort": "CDG",
+               "_id": "AA349",
+               "originPort": "ARN"
+       },
+       {
+               "miles": "11401",
+               "destPort": "JFK",
+               "_id": "AA35",
+               "originPort": "BKK"
+       },
+       {
+               "miles": "1519",
+               "destPort": "FCO",
+               "_id": "AA350",
+               "originPort": "ARN"
+       },
+       {
+               "miles": "5992",
+               "destPort": "SIN",
+               "_id": "AA351",
+               "originPort": "ARN"
+       },
+       {
+               "miles": "13627",
+               "destPort": "SYD",
+               "_id": "AA352",
+               "originPort": "ARN"
+       },
+       {
+               "miles": "2214",
+               "destPort": "IKA",
+               "_id": "AA353",
+               "originPort": "ARN"
+       },
+       {
+               "miles": "9726",
+               "destPort": "NRT",
+               "_id": "AA354",
+               "originPort": "ARN"
+       },
+       {
+               "miles": "6308",
+               "destPort": "BOM",
+               "_id": "AA355",
+               "originPort": "SYD"
+       },
+       {
+               "miles": "7795",
+               "destPort": "DEL",
+               "_id": "AA356",
+               "originPort": "SYD"
+       },
+       {
+               "miles": "13033",
+               "destPort": "FRA",
+               "_id": "AA357",
+               "originPort": "SYD"
+       },
+       {
+               "miles": "4586",
+               "destPort": "HKG",
+               "_id": "AA358",
+               "originPort": "SYD"
+       },
+       {
+               "miles": "13477",
+               "destPort": "LHR",
+               "_id": "AA359",
+               "originPort": "SYD"
+       },
+       {
+               "miles": "7810",
+               "destPort": "CDG",
+               "_id": "AA36",
+               "originPort": "BKK"
+       },
+       {
+               "miles": "12045",
+               "destPort": "YUL",
+               "_id": "AA360",
+               "originPort": "SYD"
+       },
+       {
+               "miles": "11044",
+               "destPort": "SVO",
+               "_id": "AA361",
+               "originPort": "SYD"
+       },
+       {
+               "miles": "12052",
+               "destPort": "JFK",
+               "_id": "AA362",
+               "originPort": "SYD"
+       },
+       {
+               "miles": "13249",
+               "destPort": "CDG",
+               "_id": "AA363",
+               "originPort": "SYD"
+       },
+       {
+               "miles": "12450",
+               "destPort": "FCO",
+               "_id": "AA364",
+               "originPort": "SYD"
+       },
+       {
+               "miles": "3916",
+               "destPort": "SIN",
+               "_id": "AA365",
+               "originPort": "SYD"
+       },
+       {
+               "miles": "8021",
+               "destPort": "IKA",
+               "_id": "AA366",
+               "originPort": "SYD"
+       },
+       {
+               "miles": "6904",
+               "destPort": "NRT",
+               "_id": "AA367",
+               "originPort": "SYD"
+       },
+       {
+               "miles": "1743",
+               "destPort": "BOM",
+               "_id": "AA368",
+               "originPort": "IKA"
+       },
+       {
+               "miles": "1582",
+               "destPort": "DEL",
+               "_id": "AA369",
+               "originPort": "IKA"
+       },
+       {
+               "miles": "7011",
+               "destPort": "FCO",
+               "_id": "AA37",
+               "originPort": "BKK"
+       },
+       {
+               "miles": "2342",
+               "destPort": "FRA",
+               "_id": "AA370",
+               "originPort": "IKA"
+       },
+       {
+               "miles": "4712",
+               "destPort": "HKG",
+               "_id": "AA371",
+               "originPort": "IKA"
+       },
+       {
+               "miles": "2738",
+               "destPort": "LHR",
+               "_id": "AA372",
+               "originPort": "IKA"
+       },
+       {
+               "miles": "7465",
+               "destPort": "YUL",
+               "_id": "AA373",
+               "originPort": "IKA"
+       },
+       {
+               "miles": "11537",
+               "destPort": "SVO",
+               "_id": "AA374",
+               "originPort": "IKA"
+       },
+       {
+               "miles": "7681",
+               "destPort": "JFK",
+               "_id": "AA375",
+               "originPort": "IKA"
+       },
+       {
+               "miles": "2610",
+               "destPort": "CDG",
+               "_id": "AA376",
+               "originPort": "IKA"
+       },
+       {
+               "miles": "2121",
+               "destPort": "FCO",
+               "_id": "AA377",
+               "originPort": "IKA"
+       },
+       {
+               "miles": "4110",
+               "destPort": "SIN",
+               "_id": "AA378",
+               "originPort": "IKA"
+       },
+       {
+               "miles": "9693",
+               "destPort": "SYD",
+               "_id": "AA379",
+               "originPort": "IKA"
+       },
+       {
+               "miles": "897",
+               "destPort": "SIN",
+               "_id": "AA38",
+               "originPort": "BKK"
+       },
+       {
+               "miles": "6858",
+               "destPort": "NRT",
+               "_id": "AA380",
+               "originPort": "IKA"
+       },
+       {
+               "miles": "4184",
+               "destPort": "BOM",
+               "_id": "AA381",
+               "originPort": "NRT"
+       },
+       {
+               "miles": "4959",
+               "destPort": "DEL",
+               "_id": "AA382",
+               "originPort": "NRT"
+       },
+       {
+               "miles": "9776",
+               "destPort": "FRA",
+               "_id": "AA383",
+               "originPort": "NRT"
+       },
+       {
+               "miles": "1788",
+               "destPort": "HKG",
+               "_id": "AA384",
+               "originPort": "NRT"
+       },
+       {
+               "miles": "9536",
+               "destPort": "LHR",
+               "_id": "AA385",
+               "originPort": "NRT"
+       },
+       {
+               "miles": "8199",
+               "destPort": "YUL",
+               "_id": "AA386",
+               "originPort": "NRT"
+       },
+       {
+               "miles": "4667",
+               "destPort": "SVO",
+               "_id": "AA387",
+               "originPort": "NRT"
+       },
+       {
+               "miles": "8133",
+               "destPort": "JFK",
+               "_id": "AA388",
+               "originPort": "NRT"
+       },
+       {
+               "miles": "9771",
+               "destPort": "CDG",
+               "_id": "AA389",
+               "originPort": "NRT"
+       },
+       {
+               "miles": "5774",
+               "destPort": "SYD",
+               "_id": "AA39",
+               "originPort": "BKK"
+       },
+       {
+               "miles": "9840",
+               "destPort": "FCO",
+               "_id": "AA390",
+               "originPort": "NRT"
+       },
+       {
+               "miles": "3294",
+               "destPort": "SIN",
+               "_id": "AA391",
+               "originPort": "NRT"
+       },
+       {
+               "miles": "6904",
+               "destPort": "SYD",
+               "_id": "AA392",
+               "originPort": "NRT"
+       },
+       {
+               "miles": "4770",
+               "destPort": "IKA",
+               "_id": "AA393",
+               "originPort": "NRT"
+       },
+       {
+               "miles": "230",
+               "destPort": "LHR",
+               "_id": "AA4",
+               "originPort": "AMS"
+       },
+       {
+               "miles": "3394",
+               "destPort": "IKA",
+               "_id": "AA40",
+               "originPort": "BKK"
+       },
+       {
+               "miles": "2849",
+               "destPort": "NRT",
+               "_id": "AA41",
+               "originPort": "BKK"
+       },
+       {
+               "miles": "4263",
+               "destPort": "BOM",
+               "_id": "AA42",
+               "originPort": "BRU"
+       },
+       {
+               "miles": "5679",
+               "destPort": "DEL",
+               "_id": "AA43",
+               "originPort": "BRU"
+       },
+       {
+               "miles": "190",
+               "destPort": "FRA",
+               "_id": "AA44",
+               "originPort": "BRU"
+       },
+       {
+               "miles": "8493",
+               "destPort": "HKG",
+               "_id": "AA45",
+               "originPort": "BRU"
+       },
+       {
+               "miles": "211",
+               "destPort": "LHR",
+               "_id": "AA46",
+               "originPort": "BRU"
+       },
+       {
+               "miles": "3452",
+               "destPort": "YUL",
+               "_id": "AA47",
+               "originPort": "BRU"
+       },
+       {
+               "miles": "1383",
+               "destPort": "SVO",
+               "_id": "AA48",
+               "originPort": "BRU"
+       },
+       {
+               "miles": "3662",
+               "destPort": "JFK",
+               "_id": "AA49",
+               "originPort": "BRU"
+       },
+       {
+               "miles": "3422",
+               "destPort": "YUL",
+               "_id": "AA5",
+               "originPort": "AMS"
+       },
+       {
+               "miles": "170",
+               "destPort": "CDG",
+               "_id": "AA50",
+               "originPort": "BRU"
+       },
+       {
+               "miles": "734",
+               "destPort": "FCO",
+               "_id": "AA51",
+               "originPort": "BRU"
+       },
+       {
+               "miles": "6551",
+               "destPort": "SIN",
+               "_id": "AA52",
+               "originPort": "BRU"
+       },
+       {
+               "miles": "13249",
+               "destPort": "SYD",
+               "_id": "AA53",
+               "originPort": "BRU"
+       },
+       {
+               "miles": "2525",
+               "destPort": "IKA",
+               "_id": "AA54",
+               "originPort": "BRU"
+       },
+       {
+               "miles": "9631",
+               "destPort": "NRT",
+               "_id": "AA55",
+               "originPort": "BRU"
+       },
+       {
+               "miles": "2699",
+               "destPort": "BOM",
+               "_id": "AA56",
+               "originPort": "CAI"
+       },
+       {
+               "miles": "2738",
+               "destPort": "DEL",
+               "_id": "AA57",
+               "originPort": "CAI"
+       },
+       {
+               "miles": "1815",
+               "destPort": "FRA",
+               "_id": "AA58",
+               "originPort": "CAI"
+       },
+       {
+               "miles": "6099",
+               "destPort": "HKG",
+               "_id": "AA59",
+               "originPort": "CAI"
+       },
+       {
+               "miles": "1330",
+               "destPort": "SVO",
+               "_id": "AA6",
+               "originPort": "AMS"
+       },
+       {
+               "miles": "2185",
+               "destPort": "LHR",
+               "_id": "AA60",
+               "originPort": "CAI"
+       },
+       {
+               "miles": "6514",
+               "destPort": "YUL",
+               "_id": "AA61",
+               "originPort": "CAI"
+       },
+       {
+               "miles": "1796",
+               "destPort": "SVO",
+               "_id": "AA62",
+               "originPort": "CAI"
+       },
+       {
+               "miles": "6730",
+               "destPort": "JFK",
+               "_id": "AA63",
+               "originPort": "CAI"
+       },
+       {
+               "miles": "1995",
+               "destPort": "CDG",
+               "_id": "AA64",
+               "originPort": "CAI"
+       },
+       {
+               "miles": "1329",
+               "destPort": "FCO",
+               "_id": "AA65",
+               "originPort": "CAI"
+       },
+       {
+               "miles": "5127",
+               "destPort": "SIN",
+               "_id": "AA66",
+               "originPort": "CAI"
+       },
+       {
+               "miles": "10855",
+               "destPort": "SYD",
+               "_id": "AA67",
+               "originPort": "CAI"
+       },
+       {
+               "miles": "1216",
+               "destPort": "IKA",
+               "_id": "AA68",
+               "originPort": "CAI"
+       },
+       {
+               "miles": "8245",
+               "destPort": "NRT",
+               "_id": "AA69",
+               "originPort": "CAI"
+       },
+       {
+               "miles": "3639",
+               "destPort": "JFK",
+               "_id": "AA7",
+               "originPort": "AMS"
+       },
+       {
+               "miles": "1199",
+               "destPort": "BOM",
+               "_id": "AA70",
+               "originPort": "DXB"
+       },
+       {
+               "miles": "1359",
+               "destPort": "DEL",
+               "_id": "AA71",
+               "originPort": "DXB"
+       },
+       {
+               "miles": "3008",
+               "destPort": "FRA",
+               "_id": "AA72",
+               "originPort": "DXB"
+       },
+       {
+               "miles": "3695",
+               "destPort": "HKG",
+               "_id": "AA73",
+               "originPort": "DXB"
+       },
+       {
+               "miles": "3412",
+               "destPort": "LHR",
+               "_id": "AA74",
+               "originPort": "DXB"
+       },
+       {
+               "miles": "6793",
+               "destPort": "YUL",
+               "_id": "AA75",
+               "originPort": "DXB"
+       },
+       {
+               "miles": "2303",
+               "destPort": "SVO",
+               "_id": "AA76",
+               "originPort": "DXB"
+       },
+       {
+               "miles": "6831",
+               "destPort": "JFK",
+               "_id": "AA77",
+               "originPort": "DXB"
+       },
+       {
+               "miles": "3258",
+               "destPort": "CDG",
+               "_id": "AA78",
+               "originPort": "DXB"
+       },
+       {
+               "miles": "2696",
+               "destPort": "FCO",
+               "_id": "AA79",
+               "originPort": "DXB"
+       },
+       {
+               "miles": "261",
+               "destPort": "CDG",
+               "_id": "AA8",
+               "originPort": "AMS"
+       },
+       {
+               "miles": "3630",
+               "destPort": "SIN",
+               "_id": "AA80",
+               "originPort": "DXB"
+       },
+       {
+               "miles": "7580",
+               "destPort": "SYD",
+               "_id": "AA81",
+               "originPort": "DXB"
+       },
+       {
+               "miles": "759",
+               "destPort": "IKA",
+               "_id": "AA82",
+               "originPort": "DXB"
+       },
+       {
+               "miles": "4828",
+               "destPort": "NRT",
+               "_id": "AA83",
+               "originPort": "DXB"
+       },
+       {
+               "miles": "4082",
+               "destPort": "BOM",
+               "_id": "AA84",
+               "originPort": "FRA"
+       },
+       {
+               "miles": "5463",
+               "destPort": "DEL",
+               "_id": "AA85",
+               "originPort": "FRA"
+       },
+       {
+               "miles": "8277",
+               "destPort": "HKG",
+               "_id": "AA86",
+               "originPort": "FRA"
+       },
+       {
+               "miles": "400",
+               "destPort": "LHR",
+               "_id": "AA87",
+               "originPort": "FRA"
+       },
+       {
+               "miles": "3640",
+               "destPort": "YUL",
+               "_id": "AA88",
+               "originPort": "FRA"
+       },
+       {
+               "miles": "1253",
+               "destPort": "SVO",
+               "_id": "AA89",
+               "originPort": "FRA"
+       },
+       {
+               "miles": "809",
+               "destPort": "FCO",
+               "_id": "AA9",
+               "originPort": "AMS"
+       },
+       {
+               "miles": "3851",
+               "destPort": "JFK",
+               "_id": "AA90",
+               "originPort": "FRA"
+       },
+       {
+               "miles": "289",
+               "destPort": "CDG",
+               "_id": "AA91",
+               "originPort": "FRA"
+       },
+       {
+               "miles": "598",
+               "destPort": "FCO",
+               "_id": "AA92",
+               "originPort": "FRA"
+       },
+       {
+               "miles": "6379",
+               "destPort": "SIN",
+               "_id": "AA93",
+               "originPort": "FRA"
+       },
+       {
+               "miles": "13033",
+               "destPort": "SYD",
+               "_id": "AA94",
+               "originPort": "FRA"
+       },
+       {
+               "miles": "2342",
+               "destPort": "IKA",
+               "_id": "AA95",
+               "originPort": "FRA"
+       },
+       {
+               "miles": "9776",
+               "destPort": "NRT",
+               "_id": "AA96",
+               "originPort": "FRA"
+       },
+       {
+               "miles": "4173",
+               "destPort": "BOM",
+               "_id": "AA97",
+               "originPort": "GVA"
+       },
+       {
+               "miles": "5391",
+               "destPort": "DEL",
+               "_id": "AA98",
+               "originPort": "GVA"
+       },
+       {
+               "miles": "287",
+               "destPort": "FRA",
+               "_id": "AA99",
+               "originPort": "GVA"
+       },
+       {
+               "indexes": {
+                       "n_flightsegments": {
+                               "index": "function(doc){\n\t    
index(\"default\", doc._id);\n    \t    if(doc.originPort){\n           
\tindex(\"originPort\", doc.originPort, {\"store\": \"yes\"});\n    \t    }\n   
 \t    if(doc.destPort){\n           \tindex(\"destPort\", doc.destPort, 
{\"store\": \"yes\"});\n    \t    }\n}",
+                               "analyzer": "standard"
+                       }
+               },
+               "_id": "_design/view",
+               "language": "javascript",
+               "views": {
+                       
+               }
+       }
+]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/bahir/blob/c7f158d8/sql-cloudant/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/sql-cloudant/src/test/resources/log4j.properties 
b/sql-cloudant/src/test/resources/log4j.properties
new file mode 100644
index 0000000..3706a6e
--- /dev/null
+++ b/sql-cloudant/src/test/resources/log4j.properties
@@ -0,0 +1,27 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Set everything to be logged to the file target/unit-tests.log
+log4j.rootCategory=INFO, file
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.append=true
+log4j.appender.file.file=target/unit-tests.log
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss.SSS} %t %p 
%c{1}: %m%n
+
+# Ignore messages below warning level from Jetty, because it's a bit verbose
+log4j.logger.org.spark_project.jetty=WARN

http://git-wip-us.apache.org/repos/asf/bahir/blob/c7f158d8/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/ClientSparkFunSuite.scala
----------------------------------------------------------------------
diff --git 
a/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/ClientSparkFunSuite.scala
 
b/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/ClientSparkFunSuite.scala
new file mode 100644
index 0000000..6bc5c2a
--- /dev/null
+++ 
b/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/ClientSparkFunSuite.scala
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.bahir.cloudant
+
+import java.io.{File, FileReader}
+import java.net.URL
+import java.util
+
+import com.cloudant.client.api.ClientBuilder
+import com.cloudant.client.api.CloudantClient
+import com.google.gson.{Gson, JsonArray, JsonObject}
+import org.scalatest.BeforeAndAfter
+
+import org.apache.spark.{SparkConf, SparkFunSuite}
+import org.apache.spark.sql.SparkSession
+
+import org.apache.bahir.cloudant.TestUtils.shouldRunTests
+
+class ClientSparkFunSuite extends SparkFunSuite with BeforeAndAfter {
+  private val tempDir: File = new File(System.getProperty("java.io.tmpdir") + 
"/sql-cloudant/")
+
+  var client: CloudantClient = _
+  val conf: SparkConf = new SparkConf().setMaster("local[4]")
+  var spark: SparkSession = _
+
+  override def beforeAll() {
+    runIfTestsEnabled("Prepare Cloudant test databases") {
+      tempDir.mkdirs()
+      tempDir.deleteOnExit()
+      setupClient()
+      createTestDbs()
+    }
+}
+
+  override def afterAll() {
+    TestUtils.deleteRecursively(tempDir)
+    deleteTestDbs()
+    teardownClient()
+    spark.close()
+  }
+
+  def setupClient() {
+    if (TestUtils.getHost.endsWith("cloudant.com")) {
+      client = ClientBuilder
+        .account(TestUtils.getUsername)
+        .username(TestUtils.getUsername)
+        .password(TestUtils.getPassword)
+        .build
+    } else {
+      val host = TestUtils.getProtocol + "://" + TestUtils.getHost
+      client = ClientBuilder.url(new URL(host))
+        .username(TestUtils.getUsername)
+        .password(TestUtils.getPassword)
+        .build
+    }
+  }
+
+  def teardownClient() {
+    if (client != null) {
+      client.shutdown()
+    }
+  }
+
+  def createTestDbs() {
+    // create each test database
+    // insert docs and design docs from JSON flat files
+    for (dbName: String <- TestUtils.testDatabasesList) {
+      val db = client.database(dbName, true)
+      val jsonFilePath = System.getProperty("user.dir") +
+        "/src/test/resources/json-files/" + dbName + ".json"
+      if (new File(jsonFilePath).exists()) {
+        val jsonFileArray = new Gson().fromJson(new FileReader(jsonFilePath), 
classOf[JsonArray])
+        val listOfObjects = new util.ArrayList[JsonObject]
+        if (jsonFileArray != null) {
+          var i = 0
+          while (i < jsonFileArray.size()) {
+            listOfObjects.add(jsonFileArray.get(i).getAsJsonObject)
+            i += 1
+          }
+        }
+
+        val responses = db.bulk(listOfObjects)
+        var i = 0
+        while (i < responses.size()) {
+          assert(responses.get(i).getStatusCode == 200 || 
responses.get(i).getStatusCode == 201)
+          i += 1
+        }
+
+      }
+    }
+  }
+
+  def deleteTestDbs() {
+    for (db: String <- TestUtils.testDatabasesList) {
+      client.deleteDB(db)
+    }
+  }
+
+  def deleteTestDb(dbName: String) {
+    client.deleteDB(dbName)
+  }
+
+  /** Run the test if environment variable is set or ignore the test */
+  def testIfEnabled(testName: String)(testBody: => Unit) {
+    if (shouldRunTests) {
+      test(testName)(testBody)
+    } else {
+      ignore(s"$testName [enable by setting env var CLOUDANT_USER and " +
+        s"CLOUDANT_PASSWORD]")(testBody)
+    }
+  }
+
+
+  /** Run the body of code only if tests are enabled */
+  def runIfTestsEnabled(message: String)(body: => Unit): Unit = {
+    if (shouldRunTests) {
+      body
+    } else {
+      ignore(s"$message [enable by setting env var CLOUDANT_USER and " +
+        s"CLOUDANT_PASSWORD]")(())
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/bahir/blob/c7f158d8/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantAllDocsDFSuite.scala
----------------------------------------------------------------------
diff --git 
a/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantAllDocsDFSuite.scala
 
b/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantAllDocsDFSuite.scala
new file mode 100644
index 0000000..a50b4a9
--- /dev/null
+++ 
b/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantAllDocsDFSuite.scala
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.bahir.cloudant
+
+import org.apache.spark.sql.SparkSession
+
+class CloudantAllDocsDFSuite extends ClientSparkFunSuite {
+  val endpoint = "_all_docs"
+
+  override def beforeAll() {
+    super.beforeAll()
+    spark = SparkSession.builder().config(conf)
+      .config("cloudant.protocol", TestUtils.getProtocol)
+      .config("cloudant.host", TestUtils.getHost)
+      .config("cloudant.username", TestUtils.getUsername)
+      .config("cloudant.password", TestUtils.getPassword)
+      .config("cloudant.endpoint", endpoint)
+      .getOrCreate()
+  }
+
+  testIfEnabled("load and save data from Cloudant database") {
+    // Loading data from Cloudant db
+    val df = spark.read.format("org.apache.bahir.cloudant").load("n_flight")
+    // Caching df in memory to speed computations
+    // and not to retrieve data from cloudant again
+    df.cache()
+    // all docs in database minus the design doc
+    assert(df.count() == 1967)
+  }
+
+  testIfEnabled("load and count data from Cloudant search index") {
+    val df = spark.read.format("org.apache.bahir.cloudant")
+      .option("index", "_design/view/_search/n_flights").load("n_flight")
+    val total = df.filter(df("flightSegmentId") >"AA9")
+      .select("flightSegmentId", "scheduledDepartureTime")
+      .orderBy(df("flightSegmentId")).count()
+    assert(total == 50)
+  }
+
+  testIfEnabled("load data and count rows in filtered dataframe") {
+    // Loading data from Cloudant db
+    val df = spark.read.format("org.apache.bahir.cloudant")
+      .load("n_airportcodemapping")
+    val dfFilter = df.filter(df("_id") >= "CAA").select("_id", "airportName")
+    assert(dfFilter.count() == 13)
+  }
+
+  // save data to Cloudant test
+  testIfEnabled("save filtered dataframe to database") {
+    val df = spark.read.format("org.apache.bahir.cloudant").load("n_flight")
+
+    // Saving data frame with filter to Cloudant db
+    val df2 = df.filter(df("flightSegmentId") === "AA106")
+      .select("flightSegmentId", "economyClassBaseCost")
+
+    assert(df2.count() == 5)
+
+    df2.write.format("org.apache.bahir.cloudant").save("n_flight2")
+
+    val dfFlight2 = 
spark.read.format("org.apache.bahir.cloudant").load("n_flight2")
+
+    assert(dfFlight2.count() == 5)
+  }
+
+  // createDBOnSave option test
+  testIfEnabled("save dataframe to database using createDBOnSave=true option") 
{
+    val df = spark.read.format("org.apache.bahir.cloudant")
+      .load("n_airportcodemapping")
+
+    // Saving dataframe to Cloudant db
+    // to create a Cloudant db during save set the option createDBOnSave=true
+    val df2 = df.filter(df("_id") >= "CAA")
+      .select("_id", "airportName")
+      .write.format("org.apache.bahir.cloudant")
+      .option("createDBOnSave", "true")
+      .save("airportcodemapping_df")
+
+    val dfAirport = spark.read.format("org.apache.bahir.cloudant")
+      .load("airportcodemapping_df")
+
+    assert(dfAirport.count() == 13)
+
+    deleteTestDb("airportcodemapping_df")
+  }
+
+  // view option tests
+  testIfEnabled("load and count data from view") {
+    val df = spark.read.format("org.apache.bahir.cloudant")
+      .option("view", "_design/view/_view/AA0").load("n_flight")
+    assert(df.count() == 5)
+  }
+
+  testIfEnabled("load data from view with MapReduce function") {
+    val df = spark.read.format("org.apache.bahir.cloudant")
+      .option("view", "_design/view/_view/AAreduce?reduce=true")
+      .load("n_flight")
+    assert(df.count() == 1)
+  }
+}

http://git-wip-us.apache.org/repos/asf/bahir/blob/c7f158d8/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantChangesDFSuite.scala
----------------------------------------------------------------------
diff --git 
a/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantChangesDFSuite.scala
 
b/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantChangesDFSuite.scala
new file mode 100644
index 0000000..2f74c12
--- /dev/null
+++ 
b/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantChangesDFSuite.scala
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.bahir.cloudant
+
+import play.libs.Json
+
+import org.apache.spark.sql.SparkSession
+
+class CloudantChangesDFSuite extends ClientSparkFunSuite {
+  val endpoint = "_changes"
+
+  before {
+    spark = SparkSession.builder().config(conf)
+      .config("cloudant.protocol", TestUtils.getProtocol)
+      .config("cloudant.host", TestUtils.getHost)
+      .config("cloudant.username", TestUtils.getUsername)
+      .config("cloudant.password", TestUtils.getPassword)
+      .config("cloudant.endpoint", endpoint)
+      .config("spark.streaming.unpersist", "false")
+      .getOrCreate()
+  }
+
+  after {
+    spark.close()
+  }
+
+  testIfEnabled("load and save data from Cloudant database") {
+    // Loading data from Cloudant db
+    val df = spark.read.format("org.apache.bahir.cloudant").load("n_flight")
+    // Caching df in memory to speed computations
+    // and not to retrieve data from cloudant again
+    df.cache()
+    // all docs in database minus the design doc
+    assert(df.count() == 1967)
+  }
+
+  testIfEnabled("load and count data from Cloudant search index") {
+    val df = spark.read.format("org.apache.bahir.cloudant")
+      .option("index", "_design/view/_search/n_flights").load("n_flight")
+    val total = df.filter(df("flightSegmentId") >"AA9")
+      .select("flightSegmentId", "scheduledDepartureTime")
+      .orderBy(df("flightSegmentId")).count()
+    assert(total == 50)
+  }
+
+  testIfEnabled("load data and verify deleted doc is not in results") {
+    val db = client.database("n_flight", false)
+    // Find then delete a doc to verify it's not included when loading data
+    val doc = db.find("003bd483-9f98-4203-afdd-c539a4f38d21")
+    val json = try {  Json.parse(doc) } finally { doc.close() }
+    db.remove(json.get("_id").textValue(), json.get("_rev").textValue())
+
+    val df = spark.read.format("org.apache.bahir.cloudant").load("n_flight")
+    // all docs in database minus the design doc and _deleted=true doc
+    assert(df.count() == 1966)
+
+    assert(!df.columns.contains("_deleted"))
+  }
+
+  testIfEnabled("load data and count rows in filtered dataframe") {
+    // Loading data from Cloudant db
+    val df = spark.read.format("org.apache.bahir.cloudant")
+      .load("n_airportcodemapping")
+    val dfFilter = df.filter(df("_id") >= "CAA").select("_id", "airportName")
+    assert(dfFilter.count() == 13)
+  }
+
+  // save data to Cloudant test
+  testIfEnabled("save filtered dataframe to database") {
+    val df = spark.read.format("org.apache.bahir.cloudant").load("n_flight")
+
+    // Saving data frame with filter to Cloudant db
+    val df2 = df.filter(df("flightSegmentId") === "AA106")
+      .select("flightSegmentId", "economyClassBaseCost")
+
+    assert(df2.count() == 5)
+
+    df2.write.format("org.apache.bahir.cloudant").save("n_flight2")
+
+    val dfFlight2 = 
spark.read.format("org.apache.bahir.cloudant").load("n_flight2")
+
+    assert(dfFlight2.count() == 5)
+  }
+
+  // createDBOnSave option test
+  testIfEnabled("save dataframe to database using createDBOnSave=true option") 
{
+    val df = spark.read.format("org.apache.bahir.cloudant")
+      .load("n_airportcodemapping")
+
+    // Saving dataframe to Cloudant db
+    // to create a Cloudant db during save set the option createDBOnSave=true
+    val df2 = df.filter(df("_id") >= "CAA")
+      .select("_id", "airportName")
+      .write.format("org.apache.bahir.cloudant")
+      .option("createDBOnSave", "true")
+      .save("airportcodemapping_df")
+
+    val dfAirport = spark.read.format("org.apache.bahir.cloudant")
+      .load("airportcodemapping_df")
+
+    assert(dfAirport.count() == 13)
+
+    deleteTestDb("airportcodemapping_df")
+  }
+
+  // view option tests
+  testIfEnabled("load and count data from view") {
+    val df = spark.read.format("org.apache.bahir.cloudant")
+      .option("view", "_design/view/_view/AA0").load("n_flight")
+    assert(df.count() == 5)
+  }
+
+  testIfEnabled("load data from view with MapReduce function") {
+    val df = spark.read.format("org.apache.bahir.cloudant")
+      .option("view", "_design/view/_view/AAreduce?reduce=true")
+      .load("n_flight")
+    assert(df.count() == 1)
+  }
+
+  testIfEnabled("load data and verify total count of selector, filter, and 
view option") {
+    val df = spark.read.format("org.apache.bahir.cloudant")
+      .option("selector", "{\"flightSegmentId\": {\"$eq\": \"AA2\"}}")
+      .load("n_flight")
+    val dfcount = df.count()
+    assert(dfcount == 5)
+
+    val df2 = spark.read.format("org.apache.bahir.cloudant")
+      .load("n_flight")
+    val df2count = df2.filter(df2("flightSegmentId") === "AA2")
+      .select("flightSegmentId", "scheduledDepartureTime")
+      .orderBy(df2("flightSegmentId")).count()
+    assert(df2count == dfcount)
+
+    val df3 = spark.read.format("org.apache.bahir.cloudant")
+      .option("view", "_design/view/_view/AA2").load("n_flight")
+    val df3count = df3.count()
+    assert(dfcount == df3count)
+    assert(df2count == df3count)
+  }
+}

http://git-wip-us.apache.org/repos/asf/bahir/blob/c7f158d8/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantOptionSuite.scala
----------------------------------------------------------------------
diff --git 
a/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantOptionSuite.scala
 
b/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantOptionSuite.scala
new file mode 100644
index 0000000..a8c8646
--- /dev/null
+++ 
b/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantOptionSuite.scala
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bahir.cloudant
+
+import org.scalatest.BeforeAndAfter
+
+import org.apache.spark.{SparkConf, SparkFunSuite}
+import org.apache.spark.sql.SparkSession
+
+import org.apache.bahir.cloudant.common.CloudantException
+
+class CloudantOptionSuite extends ClientSparkFunSuite with BeforeAndAfter {
+
+  after {
+    spark.close()
+  }
+
+  testIfEnabled("invalid api receiver option throws an error message") {
+    spark = SparkSession.builder().config(conf)
+      .config("cloudant.host", TestUtils.getHost)
+      .config("cloudant.username", TestUtils.getUsername)
+      .config("cloudant.password", TestUtils.getPassword)
+      .config("cloudant.endpoint", "_invalid_endpoint")
+      .getOrCreate()
+
+    val thrown = intercept[CloudantException] {
+      spark.read.format("org.apache.bahir.cloudant").load("db")
+    }
+    assert(thrown.getMessage === s"spark.cloudant.endpoint parameter " +
+      s"is invalid. Please supply the valid option '_all_docs' or '_changes'.")
+
+  }
+
+  testIfEnabled("empty username option throws an error message") {
+    spark = SparkSession.builder().config(conf)
+      .config("cloudant.host", TestUtils.getHost)
+      .config("cloudant.username", "")
+      .config("cloudant.password", TestUtils.getPassword)
+      .getOrCreate()
+
+    val thrown = intercept[CloudantException] {
+      spark.read.format("org.apache.bahir.cloudant").load("db")
+    }
+    assert(thrown.getMessage === s"spark.cloudant.username parameter " +
+      s"is empty. Please supply the required value.")
+  }
+
+  testIfEnabled("empty password option throws an error message") {
+    spark = SparkSession.builder().config(conf)
+      .config("cloudant.host", TestUtils.getHost)
+      .config("cloudant.username", TestUtils.getUsername)
+      .config("cloudant.password", "")
+      .getOrCreate()
+
+    val thrown = intercept[CloudantException] {
+      spark.read.format("org.apache.bahir.cloudant").load("db")
+    }
+    assert(thrown.getMessage === s"spark.cloudant.password parameter " +
+      s"is empty. Please supply the required value.")
+  }
+
+  testIfEnabled("empty databaseName throws an error message") {
+    spark = SparkSession.builder().config(conf)
+      .config("cloudant.host", TestUtils.getHost)
+      .config("cloudant.username", TestUtils.getUsername)
+      .config("cloudant.password", TestUtils.getPassword)
+      .getOrCreate()
+
+    val thrown = intercept[CloudantException] {
+      spark.read.format("org.apache.bahir.cloudant").load()
+    }
+    assert(thrown.getMessage === s"Cloudant database name is empty. " +
+      s"Please supply the required value.")
+  }
+}

http://git-wip-us.apache.org/repos/asf/bahir/blob/c7f158d8/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantSparkSQLSuite.scala
----------------------------------------------------------------------
diff --git 
a/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantSparkSQLSuite.scala
 
b/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantSparkSQLSuite.scala
new file mode 100644
index 0000000..41e5e89
--- /dev/null
+++ 
b/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantSparkSQLSuite.scala
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.bahir.cloudant
+
+import org.apache.spark.sql.{SparkSession, SQLContext, SQLImplicits}
+
+class CloudantSparkSQLSuite extends ClientSparkFunSuite {
+  // import spark implicits
+  private object testImplicits extends SQLImplicits {
+    protected override def _sqlContext: SQLContext = spark.sqlContext
+  }
+
+  import testImplicits._
+
+  val endpoint = "_all_docs"
+
+  override def beforeAll() {
+    super.beforeAll()
+    spark = SparkSession.builder().config(conf)
+      .config("cloudant.protocol", TestUtils.getProtocol)
+      .config("cloudant.host", TestUtils.getHost)
+      .config("cloudant.username", TestUtils.getUsername)
+      .config("cloudant.password", TestUtils.getPassword)
+      .config("cloudant.endpoint", endpoint)
+      .getOrCreate()
+  }
+
+  testIfEnabled("verify results from temp view of database 
n_airportcodemapping") {
+
+    // create a temp table from Cloudant db and query it using sql syntax
+    val sparkSql = spark.sql(
+      s"""
+         |CREATE OR REPLACE TEMPORARY VIEW airportTable
+         |USING org.apache.bahir.cloudant
+         |OPTIONS ( database 'n_airportcodemapping')
+        """.stripMargin)
+
+    // create a dataframe
+    val airportData = spark.sql(
+      s"""
+         |SELECT _id, airportName
+         |FROM airportTable
+         |WHERE _id >= 'CAA' AND _id <= 'GAA' ORDER BY _id
+        """.stripMargin)
+    assert(airportData.count() == 4)
+
+    // create filtered dataframe to compare with SQL temp. view
+    val df2 = spark.read.format("org.apache.bahir.cloudant")
+      .load("n_airportcodemapping")
+    val df2count = df2.filter(df2("_id") >="CAA" && df2("_id") <="GAA")
+      .select("_id", "airportName")
+      .orderBy(df2("_id")).count()
+
+    assert(df2count == airportData.count())
+  }
+
+  testIfEnabled("verify results from temp view of index in n_flight") {
+    // create a temp table from Cloudant index  and query it using sql syntax
+    val sparkSql = spark.sql(
+      s"""
+         |CREATE TEMPORARY VIEW flightTable
+         |USING org.apache.bahir.cloudant
+         |OPTIONS (database 'n_flight', index '_design/view/_search/n_flights')
+        """.stripMargin)
+
+    val flightData = spark.sql(
+      s"""
+         |SELECT flightSegmentId, scheduledDepartureTime
+         |FROM flightTable
+         |WHERE flightSegmentId >'AA9' AND flightSegmentId<'AA95'
+        """.stripMargin)
+    assert(flightData.count() == 25)
+
+    // create filtered dataframe to compare with SQL temp. view
+    val df2 = spark.read.format("org.apache.bahir.cloudant")
+      .load("n_flight")
+    val df2count = df2.filter(df2("flightSegmentId") > "AA9"
+      && df2("flightSegmentId") < "AA95")
+      .select("flightSegmentId", "scheduledDepartureTime")
+      .orderBy(df2("_id")).count()
+
+    assert(df2count == flightData.count())
+  }
+}

http://git-wip-us.apache.org/repos/asf/bahir/blob/c7f158d8/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/TestUtils.scala
----------------------------------------------------------------------
diff --git 
a/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/TestUtils.scala 
b/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/TestUtils.scala
new file mode 100644
index 0000000..dee6542
--- /dev/null
+++ b/sql-cloudant/src/test/scala/org/apache/bahir/cloudant/TestUtils.scala
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.bahir.cloudant
+
+import java.io.File
+
+object TestUtils {
+  // Set CouchDB/Cloudant host, username and password for local testing
+  private val host = System.getenv("CLOUDANT_HOST")
+  private val username = System.getenv("CLOUDANT_USER")
+  private val password = System.getenv("CLOUDANT_PASSWORD")
+  private val protocol = System.getenv("CLOUDANT_PROTOCOL")
+
+  // List of test databases to create from JSON flat files
+  val testDatabasesList: List[String] = List(
+    "n_airportcodemapping",
+    "n_booking",
+    "n_customer",
+    "n_customersession",
+    "n_flight",
+    "n_flight2",
+    "n_flightsegment"
+  )
+
+  def deleteRecursively(file: File): Unit = {
+    if (file.isDirectory) {
+      file.listFiles.foreach(deleteRecursively)
+    }
+    if (file.exists && !file.delete) {
+      throw new Exception(s"Unable to delete ${file.getAbsolutePath}")
+    }
+  }
+
+  // default value is https for cloudant.com accounts
+  def getProtocol: String = {
+    if (protocol != null && !protocol.isEmpty) {
+      protocol
+    } else {
+      "https"
+    }
+  }
+
+  def getHost: String = {
+    if (host != null && !host.isEmpty) {
+      host
+    } else {
+      getUsername + ".cloudant.com"
+    }
+  }
+
+  def getUsername: String = {
+    username
+  }
+
+  def getPassword: String = {
+    password
+  }
+
+  lazy val shouldRunTests = {
+    val isEnvSet = (username != null && !username.isEmpty) &&
+      (password != null && !password.isEmpty)
+    if (isEnvSet) {
+      // scalastyle:off println
+      // Print this so that they are easily visible on the console and not 
hidden in the log4j logs.
+      println(
+        s"""
+           |Sql-cloudant tests that require Cloudant databases have been 
enabled by
+           |the environment variables CLOUDANT_USER and CLOUDANT_PASSWORD.
+        """.stripMargin)
+      // scalastyle:on println
+    }
+    isEnvSet
+  }
+}

Reply via email to