How to post data to a mapquest table - mapquest

I'm trying to post data to a mapquest table and I've done everything according to their API
Here is my json:
{
"tableName": "mqap.jZ3uoAVablablabla_reported_points",
"append": true,
"returnResults": true,
"rows": [
[
{
"mqap_geography": "POINT (-123.3141509 48.4647675)",
"date": "2016-03-13T02:19:09.674Z",
"email": "anna#gmail.com",
"latitude": "48.47542496514236",
"longitude": "-123.37663650512695",
"message": "ss",
"user": "a"
}
]
]
}
Here is a screenshot of the table
And this is the response I get in Postman
{
"failures": [
{
"reason": "Either no latitude/longitude was provided, or the other information was insufficient for geocoding at or near line #0 of input.",
"row": ""
}
],
"append": true,
"returnResults": true,
"totalRows": 1,
"tableName": "mqap.jblablabla_reported_points",
"tableSize": {
"raw": 8192,
"readable": "8 KB"
},
"data": {
"rows": []
},
"failureCount": 1,
"rowCount": 0,
"info": {
"statusCode": 0,
"copyright": {
"text": "© 2015 MapQuest, Inc.",
"imageUrl": "http://api.mqcdn.com/res/mqlogo.gif",
"imageAltText": "© 2015 MapQuest, Inc."
},
"messages": []
}
}
What am I doing wrong?

The geography column should be in the table by default when the table is created: mqap_geography. This column is populated depending on information in other columns depending on their data type: Geography, [Latitude, Longitude], [Street, City, StateProvince, PostalCode, County, Country], and FullAddress. The Latitude, Longitude columns in the table above are type String so they won't populate the Geography column.

Two things I was missing:
The database NEEDS to have a geography object. So I added a latlong Geography object that I didn't end up using.
The format of the JSON should've been the following:
{
"tableName": "mqap.jZ3uoAVablablabla_reported_points",
"append": true,
"returnResults": true,
"rows": [
[
{"name":"user","value":user},
{"name":"email","value":email},
{"name":"date","value":date},
{"name":"message","value":message},
{"name":"latitude","value":latitude},
{"name":"longitude","value"longitude},
{"name":"latlong","value":"POINT(" + parseFloat(longitude) + " " + parseFloat(latitude) +")"}
]
]
}

Related

POSTGRES jsonb document GIN Indexes are created on what all objects?

I am using Postgres DB 13.5. From pgdocs -
The technical difference between a jsonb_ops and a jsonb_path_ops GIN
index is that the former creates independent index items for each key
and value in the data, while the latter creates index items only for
each value in the data. Basically, each jsonb_path_ops index item
is a hash of the value and the key(s) leading to it; for example to
index {"foo": {"bar": "baz"}}
Understanding the above in detail is important for me coz my jdata (document) is big with many keys and nested objects. Consider my json data that is stored as jsonb in a column named jdata looks like below -
{
"supplier": {
"id": "3c67b6eb-3b0d-492d-8736-66df107b83b3",
"customer": {
"type": "pro",
"name": "John George",
"address": [
{
"add-id": "098ad4df-2a90-4fda-8f92-dbe8d7196732",
"addressActive": true,
"street": "abc street",
"zip": 94044,
"staying-since": "long long",
"accessibility": {
"traffic": "heavy/congested",
"bestwaytoreach": {
"weekdays": {
"bart/metro/calltrain": true,
"price": {
"off-peak-hours": "affordable",
"peak-hours": "high"
},
"journey-time": "super-fast"
}
},
"weekends": {
"byroad": {
"ok": true,
"distance": "long",
"has-tolls": {
"true": true,
"toll-price": "relatively-high"
},
"journey-speed": "fast"
}
}
}
},
{
"add-id": "ddd1d2a0-9050-4bcf-a3ad-2e608d65e468",
"addressActive": true,
"street": "xyz street",
"zip": 10001,
"staying-since": "moved recently",
"accessibility": {
"traffic": "heavy/congested",
"bestwaytoreach": {
"weekdays": {
"subway": true,
"price": {
"off-peak-hours": "affordable",
"peak-hours": "high"
},
"journey-speed": "super-fast"
}
},
"weekends": {
"byroad": {
"ok": true,
"distance": "moderate",
"tolls": {
"has-tolls": true,
"toll-price": "relatively-high"
},
"journey-time": "super-fast"
}
}
}
}
],
"firstName": "John",
"lastName": "CRAWFORD",
"emailAddresses": {
"personal": [
"johnreplies#jg.com",
"ursjohn#jg.com",
"1234#jg.com"
],
"official": [
{
"repies-in": "1 day",
"email": "jg#jg.com"
},
{
"check's regularly": true,
"repies-in": "1 Hour",
"email": "jg-watching#jg.com"
}
]
},
"cities": [
"NYC",
"LA",
"SF",
"DC"
],
"splCustFlag": null,
"isPerson": true,
"isEntity": false,
"allowEmailSolicit": "Y",
"allowPhoneSolicit": "Y",
"taxPayer": true,
"suffix": null,
"title": null,
"birthDate": "05/10/1993",
"loyaltyPrograms": null,
"phoneNumbers-summary": [
1234567890,
1234567899,
1234567898,
1234567897
],
"phoneNumbers": [
{
"description": null,
"extension": null,
"number": 1234567890,
"countryCode": null,
"type": "Business"
},
{
"description": null,
"extension": null,
"number": 1234567899,
"countryCode": null,
"type": "Home"
}
],
"data-privacy": {
"required": true,
"laws": [
"CCPA",
"GDPR"
]
}
}
}
}
Now if I create GIN jsonb_ops index for jdata column - I want to clarify what all keys and values will be part of index.
For example - "staying-since" is a key nested at below path and it's part of "address" array too. But it's still a key, thought nested deep in the document. So will it be part of the index.
{
"supplier": {
"customer": {
"address": [
{
"staying-since": "long long" ...
And similarly "long long" is a value of a deeply nested key. Will it also be indexed.
And if GIN jsonb_path_ops index is created for jdata column --
Will a hash of "long long" value along with the path that leads to it will also be indexed.
hash(
"supplier": {
"customer": {
"address":[{"staying-since": "long long"}]
}
}
)
will the above also gets index.
I am aware about the operators that are supported by the GIN index types and am aware about the usage of these operators -
jsonb_ops ? ?& ?| #> #? ##
jsonb_path_ops #> #? ##

How to exclude some item when query with typeorm in Nestjs and Postgres

I want to build a query when i send username to server so i can exclude the record has the excludeUsers has the same username i sent.
Here is my data : `
"id": "f4830220-9912-4cbb-b685-edf4aaaf8fd5",
"createdAt": "2022-03-24T10:19:48.096Z",
"updatedAt": "2022-03-24T10:26:42.487Z",
"isDeleted": false,
"username": "vietphuongthoa98",
"link": "",
"type": "follow",
"current": 13456,
"target": 13556,
"totalPurchase": 100,
"purchasedPacks": [
{
"id": "fbb3079b-32c9-4c4b-a297-16741d1f5485",
"name": "Some packets",
"type": "follow",
"count": 2,
"price": 100,
"follows": 50,
"createdAt": "2022-03-23T07:18:22.898Z",
"isDeleted": false,
"updatedAt": "2022-03-23T09:49:30.192Z",
"description": "Some packages description.",
"originPrice": 0
}
],
"excludeUsers": [
{
"id": "9d8c25d2-8f03-46b3-92fa-b9489b943a56",
"deviceName": "iPhone 12 Pro Max",
"username": "hoaa.hanassii",
"platform": "ios",
"timeZone": 0,
"deviceAge": 21,
"subscribed": true,
"coins": 19600,
"subscriptionExpiration": "2022-04-27T00:00:00.000Z",
"isBlocked": false
}
]
Here is my query builder :
queryBuilder
.leftJoin('featured_user.excludeUsers', 'excludeUsers')
.andWhere('excludeUsers.username != :username', {
username: filter.username,
});
The actual query result is :
SELECT "featured_user"."id" AS "featured_user_id",
"featured_user"."tenant_id" AS "featured_user_tenant_id",
"featured_user"."created_at" AS "featured_user_created_at",
"featured_user"."updated_at" AS "featured_user_updated_at",
"featured_user"."is_deleted" AS "featured_user_is_deleted",
"featured_user"."username" AS "featured_user_username",
"featured_user"."link" AS "featured_user_link",
"featured_user"."type" AS "featured_user_type",
"featured_user"."current" AS "featured_user_current",
"featured_user"."target" AS "featured_user_target",
"featured_user"."total_purchase" AS "featured_user_total_purchase",
"featured_user"."purchased_packs" AS "featured_user_purchased_packs",
"featured_user"."user_id" AS "featured_user_user_id",
"excludeUsers"."username" AS "excludeUsers_username",
"excludeUsers"."id" AS "excludeUsers_id"
FROM "featured_users" "featured_user"
LEFT JOIN "featured_users_exclude_users_users" "featured_user_excludeUsers" ON "featured_user_excludeUsers"."featured_users_id"="featured_user"."id"
LEFT JOIN "users" "excludeUsers" ON "excludeUsers"."id"="featured_user_excludeUsers"."users_id"
WHERE "excludeUsers"."username" != $1 -- PARAMETERS: ["hoaa.hanassii"]
The problem is nothing response. Any ideal ? Thanks
can you add getMany() end of querybuilder and try
queryBuilder
.leftJoin('featured_user.excludeUsers', 'excludeUsers')
.andWhere('excludeUsers.username != :username', {
username: filter.username,
}).getMany()

Postgresql migrate data from jsonb array to jsonb

Let's say I have a column with this jsonb data :
{
"indicators": [
{
"year": 2019,
"indicatorsByYear": [
{
"value": 3120,
"code": "Nb_h"
},
{
"value": 18,
"code": "S_ppa"
},
{
"value": 95,
"code": "T_occ"
}
]
},
{
"year": 2020,
"indicatorsByYear": [
{
"value": 300,
"code": "Nb_h"
},
{
"value": 18,
"code": "S_ppa"
},
{
"value": 55,
"code": "T_occ"
}
]
}
],
"dataProvidedByUser": false
}
The idea is to migrate this column to a simplified object like this :
{
"indicatorsByYear": {
"2019": [
{
"value": 3120,
"code": "Nb_h"
},
{
"value": 18,
"code": "S_ppa"
},
{
"value": 95,
"code": "T_occ"
}
],
"2020": [
{
"value": 300,
"code": "Nb_h"
},
{
"value": 18,
"code": "S_ppa"
},
{
"value": 55,
"code": "T_occ"
}
]
},
"dataProvidedByUser": false
}
How can I transform the indicators array to map object with year as key and indicatorsByYear as value.
For info, the maximum number of years that I can have is 11 years (from 2010 to 2020), some columns have all the years others only some.
My attempts with something like that without success
update site
SET data = data
|| jsonb_build_object('indicatorsByYear',
jsonb_build_object(
data -> 'indicators' ->> 'year',
data -> 'indicators' ->> 'indicatorsByYear'
))
Any help would be very much appreciated! Thanks in advance.
data -> 'indicators' is an array, whose elements you need to consider individually and then aggregate back together into an object. You can use jsonb_array_elements and jsonb_object_agg respectively for this.
Also, you'll want to remove the old indicators key from the data column.
UPDATE site
SET data = jsonb_set(
data - 'indicators',
'{indicatorsByYear}',
(
SELECT jsonb_object_agg(el ->> 'year', el -> 'indicatorsByYear')
FROM jsonb_array_elements(data -> 'indicators') el
)
);

ElasticSearch Reindex API and painless script to access date field

I try to familiarize myself with the Reindexing API of ElasticSearch and the use of Painless scripts.
I have the following model:
"mappings": {
"customer": {
"properties": {
"firstName": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"lastName": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"dateOfBirth": {
"type": "date"
}
}
}
}
I would like to reindex all documents from test-v1 to test-v2 and apply a few transformations on them (for example extract the year part of dateOfBirth, convert a date value to a timestamp, etc) and save the result as a new field. But I got an issue when I tried to access it.
When I made the following call, I got an error:
POST /_reindex?pretty=true&human=true&wait_for_completion=true HTTP/1.1
Host: localhost:9200
Content-Type: application/json
{
"source": {
"index": "test-v1"
},
"dest": {
"index": "test-v2"
},
"script": {
"lang": "painless",
"inline": "ctx._source.yearOfBirth = ctx._source.dateOfBirth.getYear();"
}
}
And the response:
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source.yearOfBirth = ctx._source.dateOfBirth.getYear();",
" ^---- HERE"
],
"script": "ctx._source.yearOfBirth = ctx._source.dateOfBirth.getYear();",
"lang": "painless"
}
],
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source.yearOfBirth = ctx._source.dateOfBirth.getYear();",
" ^---- HERE"
],
"script": "ctx._source.yearOfBirth = ctx._source.dateOfBirth.getYear();",
"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Unable to find dynamic method [getYear] with [0] arguments for class [java.lang.String]."
}
},
"status": 500
}
According to this tutorial Date fields are exposed as ReadableDateTime so they support methods like getYear, and getDayOfWeek. and indeed, the Reference mentions those as supported methods.
Still, the response mentions [java.lang.String] as the type of the dateOfBirth property. I could just parse it to e.g. an OffsetDateTime, but I wonder why it is a string.
Anyone has a suggestion what I'm doing wrong?

GET request endpoint results rider_id is null

why is it that the riders have a null rider_id in the example? but the description says otherwise? riders[].rider_id : The hashed rider uuid. It doesnt say anything about it being may be null. Else what's the point of returning it. GET request
or is just an example, and the actual response has all of these ids not null
{
"product_id": "17cb78a7-b672-4d34-a288-a6c6e44d5315",
"request_id": "a1111c8c-c720-46c3-8534-2fcdd730040d",
"status": "accepted",
"surge_multiplier": 1.0,
"shared": true,
"driver": {
"phone_number": "(555)555-5555",
"sms_number": "(555)555-5555",
"rating": 5,
"picture_url": "https:\/\/d1w2poirtb3as9.cloudfront.net\/img.jpeg",
"name": "Bob"
},
"vehicle": {
"make": "Bugatti",
"model": "Veyron",
"license_plate": "I<3Uber",
"picture_url": "https:\/\/d1w2poirtb3as9.cloudfront.net\/car.jpeg"
},
"location": {
"latitude": 37.3382129093,
"longitude": -121.8863287568,
"bearing": 328
},
"pickup": {
"latitude": 37.3303463,
"longitude": -121.8890484,
"eta": 5
},
"destination": {
"latitude": 37.6213129,
"longitude": -122.3789554,
"eta": 19
},
"waypoints": [
{
"rider_id":null,
"latitude":37.77508531,
"type":"pickup",
"longitude":-122.3976683872
},
{
"rider_id":null,
"latitude":37.773133,
"type":"dropoff",
"longitude":-122.415069
},
{
"rider_id":"8KwsIO_YG6Y2jijSMf",
"latitude":37.7752423,
"type":"dropoff",
"longitude":-122.4175658
}
],
"riders": [
{
"rider_id":"8KwsIO_YG6Y2jijSMf",
"first_name":"Alec",
"me": true
},
{
"rider_id":null,
"first_name":"Kevin",
"me": false
}
]
}
The riders array, as specified in the GET /request/{request_id} reference page, is returned only for shared rides (uberPOOL rides). You will only be able to get a non-null rider_id if that rider account has already authenticated with your developer app.
This means that if any rider_id in the riders array is null, the rider account associated with that rider_id has not authenticated with your app.