You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- an example typeof
let a = async
return 2;
end async
print($a); -- async
print(typeof($a)); -- "async"
print(${await($a)}); -- 2
-- an example lambda
let test_ret = () -> begin
return 2;
end;
let res = async test_ret();
print(${await($res)}); -- 2
let test_async = (x) -> begin
return $x+2;
end;
let res1 = async test_async(1);
let res2 = async test_async(2);
print(${await([$res1, $res2])}); -- [3, 4]
-- an example of async without return and with one
let a = async
create table T1 as select 1,2 union select 2,3;
end async;
print($a); -- async
print(${await($a)}); -- None
let b = async
return (select * from table T1);
end async;
print($b); -- task
print(${await($b)}); -- [[1,2], [3,4]]
-- an example with different engines
let async1 = async
create table spark_t1 as select 'spark' on engine 'spark';
return $mixql.execution.engine;
end async;
let async2 = async
create table hive_t1 as select 'hive' on engine 'hive';
return $mixql.execution.engine;
end async;
print(await([$async1, $async2])); -- race conditions
-- an example race conditions
let x = 0;
let t1 = async
let global x = 1;
print($x); -- race conditions
return $x;
end async;
let t2 = async
let global x = 2;
print($x); -- race conditions
return $x;
end async;
let t3 = async
print($x); -- race conditions
return $x;
end async;
print(await([$t1, $t2, $t3])); -- race conditions
-- an example timeout
let ex =await(async
sleep(10); -- sleep 10 seconds
end async,
5); -- wait 5 seconds
print($ex.name); -- AsyncTimeoutException
-- an example exception
let t1 = async
raise "exp1", "task 1 failed"
end async;
let t2 = async
raise "exp2", "task 2 failed"
end async;
let res= await([$t1, $t2]);
print(res[0].name, " ", res[0].message); -- exp1 task 1 failed
print(res[1].name, " ", res[1].message); -- exp2 task 2 failed
-- an example cancel
let t1 = async
sleep(5);
return 1;
end async;
cancel($t1);
print(await($t1)); -- AsyncCanceledException
-- an example combine
let t1 = async
create table t1 as select 1 as c;
end async;
let t2 = async
create table t2 as select 2 as c;
end async;
let t3 = async
return (select sum(c) from select * from t1 union select * from t2);
end async;
let res = combine([$t1, $t2], $t3);
print(await($t3)); -- 3
--VS
let t1 = async
create table t1 as select 1 as c;
end async;
let t2 = async
create table t2 as select 2 as c;
end async;
let t3 = async
await([$t1,$t2]);
return (select sum(c) from select * from t1 union select * from t2);
end async;
print(await($t3)); -- 3
-- an example with local context
let x = 0;
let t1 = async
let x = 1;
print($x); -- 1
return $x;
end async;
let t2 = async
let x = 2;
print($x); -- 2
return $x;
end async;
let t3 = async
print($x); -- 0
return $x;
end async;
print(await([$t1, $t2, $t3])); -- [1,2,0]
print($x); -- 0
-- an example of lazy evaluation 1
let t1 = async
return (select * from super_big_table_1);
end async;
let t2 = async
return (select * from super_big_table_2);
end async;
let t3 = async
return (select * from small_table);
end async;
print(awaitFirst([$t1, $t2, $t3]));
-- an example of lazy evaluation 2
let x = 0;
let t1 = async
print($x); -- 5
let x = 1;
let t2 = async
print($x); -- 1
end async;
await($t2);
end async;
let x=5;
print(await($t1))
-- an example of running without await
let tick_tok = async
while true loop
sleep(60); -- sleep 60 seconds
print(getTime());
end loop
end async;
run($tick_tok);
print($tick_tock.isActive); -- true
let sum =(select sum(c1) from super_big_table);
print($sum);
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Beta Was this translation helpful? Give feedback.
All reactions