How can i get the result of an query from BigQuery in Airflow, and attach it into an email auto-send to me - google-bigquery

I want to use dynamic time {{ macros.ds_add(ds, 0) }}, so pandas_gbq.read_gbq doesn't work.
I also used the get_pandas_df of BigQueryHook, it showed 'BigQueryPandasConnector' object has no attribute 'http_error', the document says that I need to override DbApiHook method, but I don't know how.
And is there any solution for this issue? Appreciate for your help, guys.

Use BigQueryGetDataOperator. Following is an example:
Example: ::
get_data = BigQueryGetDataOperator(
task_id='get_data_from_bq',
dataset_id='test_dataset',
table_id='Transaction_partitions',
max_results='100',
selected_fields='DATE',
bigquery_conn_id='airflow-service-account'
)
Official Documentation: https://airflow.readthedocs.io/en/stable/integration.html#bigquerygetdataoperator

Related

Call a python method in record rule Odoo

The common syntax of record rules is ['|',('user_id','=',user.id),('user_id','=',False)]]
Is there any possiblilties we can use a python method to get the dynamic ids of user?
For Example
['|',('user_id','=',getuserid()),('user_id','=',False)]
You can try something like,
xml:
['|',('user_id','=', user.env["your.model"].get_userid().id), ('user_id','=',False)]
Py:
def get_userid(self):
domain = []
return self.env["res.user"].search(domain)
Let me know if this works for you.

How to implement conditional When method in Karate

I would like to reuse a feature both for POST-ing and PUT-ing a JSON Object. In order to achieve that I am trying to use a condition in the call:
Given param admin = admin
And request role
When method (role.id == null) ? karate.POST : karate.PUT
The error I get:
no step-definition method match found for: method (role.id == null) ? karate.POST : karate.PUT
I checked the documentation and the examples and search for the solution here, but I did not find an answer to this question.
Thanks in advance for the help.
You can use a variable for the method step:
* def action = 'GET'
* url 'https://httpbin.org/get'
* method action
Other than that I have no suggestions. I strongly advise you to not do this kind of "re-use" as it leads to un-readable and un-maintainable tests. Please read this once: https://stackoverflow.com/a/54126724/143475

Product Index Using Django ORM

I have a list of Products with a field called 'Title' and I have been trying to get a list of initial letters with not much luck. The closes I have is the following that dosn't work as 'Distinct' fails to work.
atoz = Product.objects.all().only('title').extra(select={'letter': "UPPER(SUBSTR(title,1,1))"}).distinct('letter')
I must be going wrong somewhere,
I hope someone can help.
You can get it in python after the queryset got in, which is trivial:
products = Project.objects.values_list('title', flat=True).distinct()
atoz = set([i[0] for i in products])
If you are using mysql, I found another answer useful, albeit using sql(django execute sql directly):
SELECT DISTINCT LEFT(title, 1) FROM product;
The best answer I could come up with, which isn't 100% ideal as it requires post processing is this.
atoz = sorted(set(Product.objects.all().extra(select={'letter': "UPPER(SUBSTR(title,1,1))"}).values_list('letter', flat=True)))

Mule ESB: How to do Condition checking in Datamapper using Xpath

i'm facing issue in xpath-I need do a check two attribute values, if the condition satisfies need to do hard code my own value. Below is my xml.
I need to check the condition like inside subroot- if ItemType=Table1 and ItemCondition=Chair1 then i have to give a hard coded value 'Proceed'( this hard coded value i will map to target side of datamapper).
<Root>
<SubRoot>
<ItemType>Table1</ItemType>
<ItemCondition>Chair1</ItemCondition>
<ItemValue>
.......
</ItemValue>
</SubRoot>
<SubRoot>
<ItemType>Table2</ItemType>
<ItemCondition>chair2</ItemCondition>
<ItemValue>
.......
</ItemValue>
</SubRoot>
....Will have multiple subroot
</Root>
I have tried to define rules as below, but it is throwing error
Type: String
Context:/Root
Xpath: substring("Proceed", 1 div boolean(/SubRoot[ItemType="Table1" and ItemCondition="Chair1"]))
But it is throwing error like
net.sf.saxon.trans.XPathException: Arithmetic operator is not defined for arguments of types (xs:integer, xs:boolean)
Is there any other shortcut way to perform this.Could you please help me, i have given lot more effort. Not able to resolve it. Thanks in advance.
I am not sure where you are applying this but the XPath expression you are looking for is:
fn:contains(/Root/SubRoot[2]/ItemCondition, "chair") and fn:contains(/Root/SubRoot[2]/ItemType, "Table")
So here is an example returning "Proceed" or "Stop" as appropriate:
if (fn:contains(/Root/SubRoot[1]/ItemCondition, "Chair") and fn:contains(/Root/SubRoot[2]/ItemType, "Table")) then 'Proceed' else 'Stop'
To implement the above condition , i was initially tired to do in xpath, gave me lot of error. I have implemented by simple if else condition in script part of data mapper
if ( (input.ItemType == 'Table') and (input.ItemCondition == 'chair')) {
output.Item = 'Proceed'}
else {
output.Item = 'Stop '};
Make sure about your precedence. Example, Here in the xml structure( or converted POJO) ItemType has to be checked first then followed with ItemCondition.
&& not seems to be working for me, change to 'and' operator
If you were first time trying to implement the logic. It may help you.

Magento, REST filter parametar 'from'?

when I call
$oauthClient->fetch($resourceUrl .. )
I need something like this
$resourceUrl = "www.myaps/api/rest/orders?filter[0][attribute]=created_at&filter[0][from][0]=2013-09-04 12:53:32";
But this doesn't work.
I need to take all order created after specific time? But I don't know how to use 'from' in rest API :(
Any help?
I found the answer
filter[0][attribute]=created_at&filter[0][from][0]=2012-09-04%2012:53:32"
The key is to use "%20" between date and time