I have an odd issue....
When using dynamic queries with VueFire, the query appears to run and returns data in to an array called customSiteSearch. I can console out the array and see the data there as expected.
The bit that I am struggling with is, when I evaluate the length of the customSiteSearch array after the query has run, it always returns 0 the first time. When I run the function again for a second time it appears to work. What could be the cause of this?
my code:
customSiteExists(customSite){
console.log('starting customSiteExists')
this.$bindAsArray('customSiteSearch', db.ref('slinksites/').orderByChild('customsite').equalTo(customSite) )
console.log('search result', this.customSiteSearch)
console.log(this.customSiteSearch.length)
},
Related
Consider the following query
return (self.session
.query(ItemInfo.field1, ItemInfo.field2)
.group_by(ItemInfo.field1, ItemInfo.field2)
.yield_per(yield_per)
)
This worked pretty slow so I decided to get rid off the group_by phase, staying with the following simple query:
return (self.session
.query(ItemInfo.field1, ItemInfo.field2)
.yield_per(yield_per)
)
The problem is that I do get a batch of items at once and then I need to some time for the next one.
Why?
I am writing an API test in Postman, and I would like it to succeed if a Number is returned or the string "NA".
Based on my current understanding one condition can be tested at a time, like:
pm.test('Qty returned is number', () => {
pm.expect(typeof parseInt(pm.response.json().qty)).to.be.not.equal('NaN');
});
Writing as two separate tests, one will pass and one will fail.
How can I code this exception into a single test?
Worked for my case, wanted the test to pass if one of two values is returned:
.to.be.oneOf(["value1","value2"]);
answer from jaikl
According to the BigQuery documentation listed at https://cloud.google.com/bigquery/querying-data#asynchronous-queries:
There are two types of querying via the BigQuery API. Synchronous and Asynchronous. Async works perfectly for me using the sample code provided, however synchronous does not.
The sample code I am referring to is shown if you click on the link above. What I noticed is that it does not actually wait until the results are available. If I insert a time.sleep(15) before the while True, my results return as expected. If not, then the it returns an empty result set.
The official documentation example uses the query:
"""SELECT word, word_count
FROM `bigquery-public-data.samples.shakespeare`
WHERE corpus = #corpus
AND word_count >= #min_word_count
ORDER BY word_count DESC;
"""
This query returns very quickly, however my query takes several seconds to return a result.
My question is, why does the documentation state that the run_sync_query command waits until the query completes, if the results are not actually accessible and no results are returned?
I cannot provide the query I used because it is a private data source. To produce, you just need a query that takes several seconds to run.
Looks like the request/call is timing out, not the query itself. The default time is 10s. Try setting timeout_ms in your code:
For example (I'm going to assume you are using Python):
..[auth/client setup stuff]..
query = client.run_sync_query('<your_query>')
query.timeout_ms = 60000 #set the request timeout
query.use_legacy_sql = False
query.use_query_cache = True
query.run()
..[do something with the results]..
I've not played with Ruby in a while, and was just writing a simple db query tool.
The tool connects fine and returns the correct number of results for the query (56 rows in this case), but the value returned for each element is 'nil'. Executing the query in sqlplus works fine.
I've found similar problems on StackExchange, but most of the solutions don't apply, or require using ODBC directly. Ugh.
I'm including a stripped down version of what I've written. Any ideas what I'm doing wrong?
require 'dbi'
dbh = DBI.connect('DBI:OCI8:foodb', 'user', 'password')
rs = dbh.prepare('select field_name from foo_user.cdr_fields where layout like ?')
rs.execute('phi_outage')
while rsRow = rs.fetch do
p rsRow
end
rs.finish
dbh.disconnect
The fetch method is an iterator so no need for a while loop. Try
rs.fetch do|row|
p row unless p.nil?
end
The API states that the method gets called for all remaining rows and will return nil when done.
I'm missing something simple - I do not want to access the results of this query in a view.
Here is the query:
#adm = Admin.where({:id => {"$ne" => params[:id].to_s},:email => params[:email]})
And of course when you inspect you get:
#adm is #<MongoMapper::Plugins::Querying::DecoratedPluckyQuery:0x007fb4be99acd0>
I understand (from asking the MM guys) why this is the case - they wished to delay the results of the actual query as long as possible, and only get a representation of the query object until we render (in a view!).
But what I'm trying to ascertain in my code is IF one of my params matches or doesn't match the result of my query in the controller so I can either return an error message or proceed.
Normally in a view I'm going to do:
#adm.id
To get the BSON out of this. When you try this on the Decorated Query of course it fails:
NoMethodError (undefined method `id' for #<MongoMapper::Plugins::Querying::DecoratedPluckyQuery:0x007fb4b9e9f118>)
This is because it's not actually a Ruby Object yet, it's still the query proxy.
Now I'm fundamentally missing something because I never read a "getting started with Ruby" guide - I just smashed my way in here and learned through brute-force. So, what method do I call to get the results of the Plucky Query?
The field #adm is set to a query as you've seen. So, to access the results, you'll need to trigger execution of the query. There are a variety of activation methods you can call, including all, first, and last. There's a little documentation here.
In this case, you could do something like:
adm_query = Admin.where({:id => {"$ne" => params[:id].to_s},:email => params[:email]})
#adm_user = adm_query.first
That would return you the first user and after checking for nil
if #adm_user.nil?
# do something if no results were found
end
You could also limit the query results:
adm_query = Admin.where( ... your query ...).limit(1)