When building a Java GraphQL API , how can I avoid Over-Fetching from the DB (i.e. fetching only for the fields specified in the query)? - api

In most example I saw there I need to implement a fletcher for each type I.e. having one generic query for each type.
As one of the promises of GraohQL is reducing load on the server, I wonder how can I customize the query to the DB in a way it will fetch only the fields the user specify in the GraphQL query.
I know I can fetch all possible fields, but this looks to me like missing the point.

I don't know this specific java implementation but it will be similar to other solutions.
You have to use additional, contextual informations available to optimize DB queries. According to docs you're probably looking for DataFetchingEnvironment

Related

How to sort all lists in a specific bin in Aerospike using aql?

I have a few question about ordered lists in Aerospike:
How can I see in the DB, using aql, if the list is ordered or not?
Does ordered list means it’s sorted?
I want to scan the db and change all lists (in a specific bin) to be ordered. I want to do is using set_type, but I can’t seem to make it work. Is that possible? how can I do it?
Thanks
I'm posting my answer from your cross-posted question here https://discuss.aerospike.com/t/list-oprations/5282:
You could scan the namespace with a ScanPolicy.includeBinData=false and for each record digest you get back use operate() to wrap the following operations into a single transaction:
ListOperation.setOrder() to ListOrder.ORDERED
ListOperation.sort() with a ListSortFlags.DROP_DUPLICATES
You will only need to run this once to clean up your database.
The ordering type will stick for all future operations. You'd just continue to use the ListWriteFlags.ADD_UNIQUE list policy.
This is for the Java client, but all other clients have these operations and policies in them.
I don't think AQL is the right tool to exploit the full power of lists. Perhaps it is not yet updated to the full functionality of lists. It is built on top of the C client. At least AQL ver 3.15.2.1 that I checked with is not. You might want to write a java client application.

Paginate through BigQuery query results using python

I see that the BigQuery REST API allows for pagination through results, and I see that the BigQuery python client allows pagination when listing rows in a table (among other things), but I do not see a way to paginate through query results.
The Job makes a call to client.list_rows, but does not give the caller the option of passing in max_results:
https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/bigquery/google/cloud/bigquery/job.py#L2404
It also does not expose sufficient information, as far as I can tell, to be able to build the Table definition (I don't see where to get the query schema) external to the Job and make the list_rows call myself.
Hopefully I'm just missing something...
Help would be greatly appreciated,
--Ben
jobs.getQueryResults do support a page token:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/getQueryResults

Deleting rows in datastore by time range

I have a CKAN datastore with a column named "recvTime" of type timestamp (i.e. using "timestamp" as type at datastore_create time, as shown in this link). Example value for this column is "2014-06-12T16:08:39.542000".
I have a large numbers of records in the datastore (thousands) and I would like to delete the rows before a given date in "recvTime". My first thought was doing it using the REST API with the datastore_delete operation using a range filter, but it is not possible as described in the following Q&A.
Is there any other way of solving the issue, please?
Given that I have access to the host where CKAN server is running, I wonder if this could be achieved executing a regular SQL sentence on the Postgresql engine where the datastore is persisted. However, I haven't found information about manipulating the CKAN underlying datamodel in the CKAN documentation, so don't know if this a good idea or if it is risky...
Any workaround or information pointer is highly welcome. Thanks!
You could definitely do this directly on the underlying database if you were willing to dig in there (the structure is pretty simple with tables named after the corresponding resource id). You could even turn this into an API of your own using an extension (though you'd want to be careful about permissions).
You might also be interested in the new support (master only atm) for extending the DataStore API via a plugin in an extension - see https://github.com/ckan/ckan/pull/1725

Is it possible to store and retrieve objects created using Objective-C? (in a database, for use in iOS app)

I'm working on an iOS app that creates "location sets" where each row contains a location name and a GeoPoint, and each set has its own name. Each of these sets are stored in an object inside our program (all belonging to the same class). Now we want to give users the capability to create sets and upload them to a database, allowing other users to access and download them to their device.
I've been looking in to back-end solutions for work like this, but pretty much everything I've found so far focuses on relational databases and adding and deleting rows and using SQL-like language to retrieve them. Is there a way to store these objects just as objects (and not unpack the info inside to tables), and then retrieve them? It feels like that would be a much simpler way of going about this.
I'm an absolute beginner when it comes to databases, so forgive me if there's info missing here that you would need to help me out. I'll make sure to keep checking back in case someone asks for more info.
Thanks!
Coredata might be useful for you as its based upon the entity. So you can play multiple things around it by using queries (predicates).
But if you just want to save and retrieve back, then as a simplest solution I would suggest to create array/dictionary with entity data, save that into NSUserDefaults so you can retrieve back same while re-launching the app.
Webservices for iOS development:
raywenderlich
icodeblog
WSDL Webservices
Response data parsing, it would be either JSON or XML:
JSON Parsing
XML Parsing
Hope these links would be helpful for you.
I ended up using Parse's mobile back-end service. That was the type of service I was looking for. I've found other similar services since then, like Applilcasa and StackMob, but we're pretty happy with Parse so far.

Ajax autocomplete extender populated from SQL

OK, first let me state that I have never used this control and this is also my first attempt at using a web service.
My dilemma is as follows. I need to query a database to get back a certain column and use that for my autocomplete. Obviously I don't want the query to run every time a user types another word in the textbox, so my best guess is to run the query once then use that dataset, array, list or whatever to then filter for the autocomplete extender...
I am kinda lost any suggestions??
Why not keep track of the query executed by the user in a session variable, then use that to filter any further results?
The trick to preventing the database from overloading I think is really to just limit how frequently the auto updater is allowed to update, something like once per 2 seconds seems reasonable to me.
What I would do is this: Store the current list returned by the query for word A server side and tie that to a session variable. This should be basically the entire list I would think. Then, for each new word typed, so long as the original word A exists, you can filter the session info and spit the filtered results out without having to query again. So basically, only query again when word A changes.
I'm using "session" in a PHP sense, you may be using a different language with different terminology, but the concept should be the same.
This question depends upon how transactional your data store is. Obviously if you are looking for US states (a data collection that would not change realistically through the life of the application) then I would either cache a System.Collection.Generic List<> type or if you wanted a DataTable.
You could easily set up a cache of the data you wish to query to be dependent upon an XML file or database so that your extender always queries the data object casted from the cache and the cache object is only updated when the datasource changes.
RAM is cheap and SQL is harder to scale than IIS so cache everything in memory:
your entire data source if is not
too large to load it in reasonable
time,
precalculated data,
autocomplete webservice responses.
Depending on your autocomplete desired behavior and performance you may want to precalculate data and create redundant structures optimized for reading. Make use of structs like SortedList (when you need sth like 'select top x ... where z like #query+'%'), Hashtable,...
While caching everything is certainly a good idea, your question about which data structure to use is an issue that wasn't fully answered here.
The best data structure for an autocomplete extender is a Trie.
You can find a good .NET article and code here.