taskid tasktitle assigned to
1 A DEMO
2 B TEST
3 C DEMO,TEST
$caccess= $user->authorise('core.admin');
if( !$caccess ) {
$query->where('task.assignedto='.$user->id);
}
I placed the above code in ListQuery Function in model but only task A is coming for DEMO USER.
I need TASK A and TASK C For DEMO USER and TASK B and TASK C for TEST USER.
In the database , assigned field are stored like demo,test for TASK C.
How should I write the retrieval query?
Related
I have three tables:
PhaseTasks
phaseId
taskId
1
1
1
2
2
4
Tasks
taskId
taskName
defaultResource
1
Do a thing
1
2
Do another thing
1
3
do some other thing
2
resources
id
name
1
Engineering
2
Support
2
Sales
I am trying to get a result set where i can print
Phase Id: 1, TaskName: Do a thing, ResourceName: Engineering
Phase Id: 1, TaskName: Do another thing, ResourceName: Engineering
Here is my phaseTasks Model:
public function phaseTasks(){
return $this->hasManyThrough(
resources::class,
tasks::class,
'id',
'id',
'taskId',
'defaultResource'
);
}
and my controller:
$phaseData = phaseTasks::with('phaseTasks')->where('phaseId','1')->get();
i cant get the task table info, nor can i figure out how to access the resource data. I DO see the resource data in the print_r($phaseData), i do not see the tasks stuff, im guessing i need to get into pivots for that part.
***EDIT
I was able to figure out how to get the resources.name entity
$phaseData[0]->phaseTasks[0]->name;
now i just need to figure out how to get the taskName entity.
I'm not sure but I think you got the relationship the other way around: it's not hasmany (through) but belongs to.
So, phasetasks - task_id belongs to a task - default resource belongs to a resource
And your phasetasks looks like a pivot table in itself, but that may be ok.
So if you agree with my assumption and create the relations my way, try something like
PhaseTask::with('task.resource')->get();
We have a stored procedure which alter session and set query_tag parameter to some value. When this procedure is called directly through call statement the query tag is setting, whereas when this procedure is called through task, the query tag is not setting. Please suggest.
CREATE OR REPLACE TASK mytask
WAREHOUSE = COMPUTE_WH
SCHEDULE = '1 minute'
AS CALL dummy();
create or replace procedure dummy()
RETURNS VARCHAR(50)
LANGUAGE JAVASCRIPT
EXECUTE AS CALLER
as $$
snowflake.execute( {sqlText: "ALTER SESSION SET QUERY_TAG = 'execute_dummy_proc'" } );
var sql_command = "INSERT INTO mytable(ts) VALUES(CURRENT_TIMESTAMP())";
snowflake.execute ({sqlText: sql_command});
$$;
I reused the provided code. Just changed the second query in your task for a basic select to make it more simple.
CREATE OR REPLACE TASK mytask
WAREHOUSE = COMPUTE_WH
SCHEDULE = '1 minute'
AS CALL dummy();
create or replace procedure dummy()
RETURNS VARCHAR(50)
LANGUAGE JAVASCRIPT
EXECUTE AS CALLER
as $$
snowflake.execute( {sqlText: "ALTER SESSION SET QUERY_TAG = 'execute_dummy_proc'" } );
var sql_command = "SELECT 1";
snowflake.execute ({sqlText: sql_command});
$$;
As you can see in screenshot below, there is two consecutive runs of the task and every time the secund query (SELECT 1) is effectively tagged.
In Snowflake each task executes in a new session so query tag only appear after the alter session.
I see nothing wrong here. Just in case you have the possibility to set your variable session in TASK creation.
For exemple
CREATE OR REPLACE TASK mytask
WAREHOUSE = COMPUTE_WH
SCHEDULE = '1 minute'
QUERY_TAG = 'mytag'
AS CALL dummy();
the queries run by certain role cannot be viewed in history using another role lower in hierarchy. To fix this, we gave below grant on the warehouse being used by task: GRANT MONITOR ON WAREHOUSE CUSTOM_WH TO ROLE "DEVELOPER ROLE";
After this, we were able to see queries ran by task and getting the query tag set.
I am implemented airflow , can we add data sanity logic. suppose I have Task1 which do the following task
1.Read the data from the data source--RAW DATA.
2. do join with dimensional table to get the some relation detail product name etc.
3. Store output file some location after step 2.
There is a task2 that stored the output file into database. but before task2 execution i need to some data validation like count of RAW DATA should equal to the store output file count i.e after joining
like count(raw_data) = count(raw_data_join_with_dimensional) , if it is true then trigger the Task2 else send the alert and failed the job.
For that use case a possible workflow could be:
check_op = SQLCheckOperator(
task_id='check_task',
sql='YOUR VALIDATION SQL',
conn_id='YOUR CONN',
)
t2_op = YourNextOperator()
failure_op = EmailOperator(subject='check has failed', to='YOUR EMAIL', trigger_rule='one_failed')
check_op >> [t2_op, failure_op]
It works as follows:
SQLCheckOperator runs the query against the DB. If query returns False the check has failed thus the operator will be in Failure state. If the query returns value the query consider as success thus the operator will be in Success state.
EmailOperator will be triggered if SQLCheckOperator status is failure otherwise YourNextOperator will be triggered.
Edit: Go see #Elad's answer, there's a much more specific operator for this task.
The airflow.sensors.sql_sensor.SqlSensor can be used to build a task that can check data quality:
from airflow.sensors import sql_sensor
...
check_data_task = sql_sensor.SqlSensor(
task_id="check_data",
conn_id="YourConnectionIdentifier",
sql="SELECT CASE WHEN data_is_valid THEN 1 ELSE 0 END ...",
timeout=0
)
The key being that your sql argument return "at least one cell that contains a non-zero / empty string value" -- according to the documentation. The timeout=0 means that it will check once and fail if your data check query doesn't "pass"
I have some functional tests created via JMeter. It is pretty huge but i can't handle one simple check.
I generate properties using BSF pre processor with help of JS. Parameter (lets call it "payment_fee") should be generated only if other parameter (lets call it "role") has a value = 1 .In this case we post pre generated integer into payment_fee and everything works well. But if role =2 then we should post nothing into payment_fee.
The problem is, i don't know how to say to JMeter: In case if role = 1 use variable with pre generated payment_fee but if role = 2, you shouldn't use this variable so just post an empty value for payment_fee . Server waits for an integer so empty string or NULL had been rejected.
For more clarification:
I will try to explain more clear.
Here is a part of my code
var role = Math.floor(Math.random()*3+1)
var paymentType = ["creditcard","cash"]
var randomPay = installerType[Math.floor(Math.random()*installerType.length)];
var payment = "";
var paymentFee;
if (role == 1){
payment+=randomPay,
paymentFee = Math.floor((Math.random() * 999) + 1) / 10.00
}
vars.put("role", role);
vars.put("payment", payment);
vars.put("paymentFee", paymentFee);
And if role == 1 i should post paymentFee value. Like this - http://prntscr.com/b50kk1 BUT! if role == 2 || role == 3 I should remove this value, so it should be like this http://prnt.sc/b50l82
I don't fully understand what you're trying to do as your 2 statements clash:
But if role =2 then we should post nothing into payment_fee
Server waits for an integer so empty string or NULL had been rejected
You should know few bits about JMeter properties:
Properties are global for the whole JVM. Once you set property it will "live" until you exit JMeter.
Properties can be accesses by all threads of all Thread Groups.
So it might be the case when you define property earlier or by another thread and expect it to be not set later on.
Also BSF PreProcessor and JavaScript isn't the best combination from performance perspective, consider switching to JSR223 PreProcessor and Groovy language.
In my WPF application, I have a Data Grid which populates with a ObservableCollection collection. Suppose I have such 10 student data in the grid. Each student is capable of doing 2 long running works or process and updates the status of the process back to the grid. I want to do those 2 process simultaneously. So I used Task and Parallel.Invoke methods. The work flow is as follows.
I populated the Student data collection in the Grid.
I clicked on a start button.
In the click event of the start button, i did the following code.
foreach (Student stud in StudentLists)
{
stud.Status = "started..";
Task.Factory.StartNew(() => StartProcess(stud));
}
In the StartProcess,
Parallel.Invoke(() =>
{
MarkService ms = new MarkService(stud_data);
Student s = ms.GetMarkProcess(); // This will return the stud_data in the above line
Student studitem = StudentLists.Where(x => x.RollID == s.RollID).FirstOrDefault(); // find the student in the grid
if (studitem != null)
{
studitem.Status = "Mark Got it"; // if find, updating the status
}
},
() =>
{
SentMarks(poll); // this is another method to be executed parallel
}
);
When executing all the 10 students process, each student in the grid became the same data.
Or only 2 or 1 student in the Grid is showing Status "Mark Got it". Other rows show "started.." status only.
Why this is not updating the collection.
I have used INotofyPropertyChanged and raisng the event when property updated.
In the XAML, each binding is used in Two way mode.
There is no error. But the 1 or 2 items in the student collection is updating some times. Sometimes the collection contains the last students data for all the 9 items.
It is not updating the exact student object in the Grid. what is wrong in my code ?
Any help in this case ???
The problem here is that your referencing a UI control from another thread. You should create an in memory data structure that a grid can use as DataSource (anything that implements IEnumerable). I would suggest using the ConcurrentBag data structure for parallelized code (http://msdn.microsoft.com/en-us/library/dd997305.aspx). Once you've updated each of the student records in the ConcurrentBag you set the grid's datasource to that bag.