CQL query to fetch data from multiple search criteran value - cassandra

with big hope asking this question.geeks please suggest..
I have huge data stored into cassandra, with all US cities, state,lat and long. what would be the cql query to get lat and long of multiple city in multiple state.
sample req
{
"city": "Northbrook",
"state": "IL"
},
{
"city": "Chicago",
"state": "IL"
},
{
"city": "Schaumburg",
"state": "IL"
},
{
"city": "Omaha",
"state": "NE"
},
{
"city": "Bellevue",
"state": "NE"
},
{
"city": "Paige",
"state": "AZ"
}
Query used : select * from tablename where city in ('Northbrook','Paige','Chicago','Bellevue','Omaha','Schaumburg') and state in ('IL','AZ','NE')
problem is, it's not returning all six cities lat and long and other details. Can anyone help me here ?

Related

Query array values in cosmos collection

I am new to cosmos db and I have done a lot of SQL. I would like to know how can I query cosmos collection properties that is an array.
For example:
Cosmos Data
"id": "123",
"addressArray": {
"date": null,
"type": "Home",
"addresses": [
{
"type": "ALL",
"city": "London"
},
{
"type": "City",
"city": "Paris"
},
{
"type": "City",
"city": "New York"
}
],
"Use": null
}
Now I want to write a query in cosmos to find addresses in Paris and New York where Type is city
Select * from c where c.addressArray.addresses[0] = "New York"
What should be the query when there is an array?
You need this?
SELECT value city
FROM Games g
JOIN city IN g.addressArray.addresses
WHERE city.city = 'New York' OR city.city='Paris'

How to query a property with a dash in CosmosDB SqlAPI?

Query: I wanted to get the list of records for all people born in the month of March.
{
"details": {
"state": "CA",
"city": "San Fransisco",
"date-of-birth": { // there is a "-" in the key
"month": "March",
"year": "2000"
}
},
"personId": "person1",
"id": "id1"
},
{
"details": {
"state": "CA",
"city": "San Jose",
"date-of-birth": { // there is a "-" in the key
"month": "April",
"year": "2000"
}
},
"personId": "person2"
"id": "id2"
}
I was hoping that the SQL Query would be like this, but got an error :
select * from c where c.details['date-of-birth'['month']] = "March"
Can someone help me out with the query? I did try to look at the docs but got a little bit confused.
Try this
select * from c where c.details['date-of-birth'].month = "March"

Stripe Charges vs Orders clarifications

I'm implementing a payment platform with Stripe.
For a single payment I create a Charge.
It works, no problem, but I also need to apply a tax fee to the product which is defined in the Order object.
Does that mean I need to replace Charges with Orders somehow or is Order a parent object for the charge? If so how do I link those 2 together? Or there is a way to apply tax fees to charges I didn't see?
Thanks
EDIT:
public async Task<StripeCharge> CreateStripeChargeAsync(StripeProduct product, StripeSku sku, StripeCustomer customer, string orderId)
{
var charge = await _chargeService.CreateAsync(new StripeChargeCreateOptions
{
Amount = sku.Price,
Currency = sku.Currency,
Description = product.Description,
CustomerId = customer.Id,
SourceTokenOrExistingSourceId = customer.DefaultSourceId,
ReceiptEmail = customer.Email,
Metadata = new Dictionary<string, string>
{
{ "OrderId", orderId }
}
});
return charge;
}
You can add a tax to your order by creating an order item with the type set to tax, for example
Stripe\OrderItem JSON: {
"object": "order_item",
"type": "tax",
"amount": 1234,
"currency": "usd",
"description": "Tax",
"parent": "null",
"quantity": null
}
Attach this to your orders item list. I can't really give a code example since you didn't mention a language but your order object would look like...
Stripe\Order JSON: {
"id": "or_1CZfbeCAQSQw5dVw1BSP63dZ",
"object": "order",
"amount": 1500,
"amount_returned": null,
"application": null,
"application_fee": null,
"charge": null,
"created": 1528206830,
"currency": "usd",
"customer": null,
"email": null,
"items": [
{
"object": "order_item",
"amount": 10000,
"currency": "usd",
"description": "My Product name",
"parent": "sk_1BQuNoCAQSQw5dVwjf30OpxH",
"quantity": null,
"type": "sku"
},
"object": "order_item",
"type": "tax",
"amount": 1234,
"currency": "usd",
"description": "Tax",
"parent": "null",
"quantity": null
], etc...
You can use the same idea for adding shipping costs or even applying discounts by using type="shipping" or "discount".
Notice the order object contains a charge field. Once the order is paid this is populated with the charge id. No need to replace charges with orders, Stripe will do this update for you linking the payment to the order.
See the API Docs for more information.

Node/Mongo autocomplete with search on two fields

I am using Node/Express/Mongo/Mongoose/jQuery/jQuery UI Auto-complete. I have a collection of Businesses that look like this:
[
{
name: "Example Corporation",
"address": {
"city": "New York",
"state: "NY"
},
{
name: "ABC Corp",
"address": {
"city": "Atlanta",
"state: "GA"
},
{
name: "ACME Inc",
"address": {
"city": "Dallas",
"state: "TX"
},
{
name: "New York Company",
"address": {
"city": "New York",
"state: "NY"
},
{
name: "XYZ Co",
"address": {
"city": "Newark",
"state: "NJ"
}
}
]
I want to create an auto-complete that would allow someone to type in the partial name of the business name OR city and get results back grouped like so:
If I search "New" I want:
{
businesses: [
{
name: "New York Company",
address: {
"city": "New York",
"state": "NY"
}
},
{
name: "XYZ Co",
address: {
"city": "Newark",
"state": "NJ"
}
}
],
cities: [
{
"city": "New York",
"state": "NY"
},
{
"city": "Newark",
"state": "NJ"
}
]
}
Very similar to an auto-complete search you might see on OpenTable where you can search by restaurant or location. I want unique city names returned.
Do I need to search the collection twice per business name and city and tie it all together at the end? I'm so confused. I don't need ID's back since the end result they either go to a City page or the Business page. I hope this makes sense.

Core data relations between objects

Please suggest about how to create relation in Core Data in the following situation: I created a user object which contained 2 relations pointing to the same object (address) but relation names are homeAddress and workAddress. But on Xcode5 it gives some warning that the inverse relation is not reciprocal.
JSON:
{
"user": {
"user_id": "123123",
"email": "user#email.com",
"first_name": "Jean Luc",
"last_name": "Picard",
"home_address": {
"street": "DowningStreet",
"number": "11",
"city": "London",
"state": "GreaterLondon",
"country": "UnitedKingdom",
"zip": "SW1A2QAB",
"name": "Homesweethome",
"created_at": "1365526421456",
"location": {
"latitude": 3.1,
"longitude": 3.2
}
},
"work_address": {
"street": "AmphitheatreParkway",
"number": "1600",
"city": "MountainView",
"state": "California",
"country": "UnitedStates",
"zip": "94043",
"name": "WorkHarder",
"created_at": "1365526642123",
"location": {
"latitude": 3.1,
"longitude": 3.2
}
}
}
}
I want to avoid creating 2 separate address objects.

Resources