Data flow - CSV to CosmosDB - decimal or float geospatial data

Andrew Lightfoot 6 Reputation points
2020-08-14T07:51:08.767+00:00

Hello

In a dataflow with a CSV source and CosmosDB sink I want to map the Long/Lat fields to a point array in CosmosDB so I can use geospatial queries.

It should look like this:

"location":{
    "type":"Point",
    "coordinates":[ 0.1055987, -4.8 ]
}

When I first did this the mapping retained the values as strings (so ["0.1055987", "-4.8" ]) and the geospatial queries didn't work - which I believe is because the values need to be numbers, not strings.

However when I try and convert the values to either decimals or floats (eg toFloat(LONGITUDE, '##.#######') ) I get this error when the data flow runs: Cannot cast 0.1055987 into a Json value. FloatType has no matching Json

I get the same error for decimals.

The Long/Lat values are decimals eg 0.1055987

Any help would be appreciated!

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,832 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Kiran-MSFT 691 Reputation points Microsoft Employee
    2020-08-17T03:20:15.423+00:00

    You need to create an array to represent [ 0.1055987, -4.8 ]. Say you have two columns in your CSV called longitude and latitude you can use structure and array creation.

    A expression like

    @(
    type = 'Point'
    coordinates = [latitude, longitude]
    )

    assign this to a column called "location" in a derived tx.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.