开发者

Erlang: qlc:info throws an error while qlc:eval does not - why?

Works

root@test # erl
Erlang R14B02 (erts-5.8.3) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [kernel-poll:false]

Eshell V5.8.3  (abort with ^G)
1> Tmp = ets:new(test, [bag]), Ref = make_ref(),
1> qlc:eval(qlc:q([Ref1 || Ref1 <- ets:table(Tmp), Ref =:= Ref1])).
[]
2> qlc:info(qlc:q([Ref1 || Ref1 <- ets:table(Tmp), Ref =:= Ref1])).
"ets:table(16400,\n          [{traverse,\n            {select,\n             [{'$1',\n               [{'=:=',{const,#Ref<0.0.0.29>},'$1'}],\n               ['$1']}]}}])"
3> halt().

Does not work

root@t开发者_如何学运维est # erl
Erlang R14B02 (erts-5.8.3) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [kernel-poll:false]

Eshell V5.8.3  (abort with ^G)
1> Tmp = ets:new(test, [bag]), Ref = make_ref(),
1> qlc:eval(qlc:q([Ref1 || {Ref1} <- ets:table(Tmp), Ref =:= Ref1])).
[]
2> qlc:info(qlc:q([Ref1 || {Ref1} <- ets:table(Tmp), Ref =:= Ref1])).
** exception error: no match of right hand side value {error,{1,erl_parse,["syntax error before: ",["Ref"]]}}
     in function  qlc:abstract/3
     in call from qlc:abstract/3
     in call from qlc:abstract/4
     in call from qlc:info/2
3> halt().

I can't understand why. Discovered this error on a much more complex query that I'm not able to explain and profile because of this error.


Even though the post is very old, I wanted to understand the behavior. Please correct me wherever there is something wrong in my understanding.

Consider the following change in the code

1> Tmp = ets:new(test, [bag]), Ref = my_own_ref,
qlc:info(qlc:q([Ref1 || Ref1 <- ets:table(Tmp), (Ref1 =:= Ref) ])).
"ets:table(16400,\n          [{traverse,\n            {select,[{'$1',[{'=:=','$1
',{const,my_own_ref}}],['$1']}]}}])"
2> qlc:info(qlc:q([{Val1} || {Ref1,Val1} <- ets:table(Tmp), (Ref1 =:= Ref) ])).
"ets:match_spec_run(ets:lookup(16400, my_own_ref),\n                   ets:match
_spec_compile([{{'$1','$2'},[],[{{'$2'}}]}]))"

The change in the output is that match_spec_run is used in the second case(qlc handles are different). This means there is a change how the qlc info needs to get the data from the qlc handle.

The below code gives error

1> Tmp = ets:new(test, [bag]), Ref = make_ref().
#Ref<0.0.0.25>
2> qlc:info(qlc:q([{Val1} || {Ref1,Val1} <- ets:table(Tmp), (Ref1 =:= Ref) ])).
** exception error: no match of right hand side value
                    {error,{1,erl_parse,["syntax error before: ",["Ref"]]}}
     in function  qlc:abstract/3 (d:/workspace/test/src/qlc.erl, line 1177)
     in call from qlc:abstract/3 (d:/workspace/test/src/qlc.erl, line 1196)
     in call from qlc:abstract/4 (d:/workspace/test/src/qlc.erl, line 1142)
     in call from qlc:info/2 (d:/workspace/test/src/qlc.erl, line 445)

When debugging the code of qlc found that, for match_spec_run related query handle the qlc:info uses abstract format function erl_parse:parse_exprs/1 to get the parse tree. But the problem in this case is that the Erlang reference has no parse tree!! For simple understanding NewRef = #Ref<0.0.0.134>. and also pid NewPid = <0.34.0>. gives syntax error, they can only be values bound to a variable and compiler cannot interpret/parse them. Thus in this case it results in the error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜