PQL Questions

247 views
Skip to first unread message

R.I.Pienaar

unread,
Jul 10, 2016, 4:33:03 PM7/10/16
to puppet-users
hey,

Been playing with the PQL language and it's quite nice, have 2 questions.

I want to do a regex case insensitive match, docs mention you can do whatever
Postgres supports but I can't figure out how to do case insensitive matches
with PQL?

Postgres supports ~ and ~* operators but PQL only supports ~. So I suppose
I could match [aA][bB][cC] to get case insensitivity, but thats a tad ugly

Next I have a fact like:

foo => { bar => ["a", "b", "c"]}

How do I search into that where bar contains "b"? There's an "in" operator
but I can't seem figure out both how to search inside the sub hash and also
how to match inside a array like that?


---
R.I.Pienaar

Wyatt Alt

unread,
Jul 10, 2016, 6:39:46 PM7/10/16
to puppet...@googlegroups.com, R.I.Pienaar



On 07/10/2016 01:32 PM, R.I.Pienaar wrote:
> hey,
>
> Been playing with the PQL language and it's quite nice, have 2 questions.
>
> I want to do a regex case insensitive match, docs mention you can do whatever
> Postgres supports but I can't figure out how to do case insensitive matches
> with PQL?
>
> Postgres supports ~ and ~* operators but PQL only supports ~. So I suppose
> I could match [aA][bB][cC] to get case insensitivity, but thats a tad ugly
Hey R.I,

I agree -- the docs are incorrect here and if you link the page you're
looking at I'll change them. PuppetDB currently only supports postgres's
~ operator, but I think adding support for ~* would be a good feature
and technically easy, so I've created
https://tickets.puppetlabs.com/browse/PDB-2861 to address it. For now
your hack is probably the best you can do.
>
> Next I have a fact like:
>
> foo => { bar => ["a", "b", "c"]}
>
> How do I search into that where bar contains "b"? There's an "in" operator
> but I can't seem figure out both how to search inside the sub hash and also
> how to match inside a array like that?
Querying structured facts in PQL is still pretty inconvenient in some
cases, but you could do this with something like

fact_contents{path ~> ["foo", "bar", "\\d"] and value = "b"}

This can be inserted as a subquery to get the certnames associated with
such a value, e.g

nodes{certname in fact_contents[certname]{path ~> ["foo", "bar", "\\d"]
and value = "b"}}

Incidentally, we have two tickets in flight (PDB-2632 and PDB-2633) that
will enable the nicer syntax

inventory{facts.foo.bar.match("\\d") = "b"}

to do the same thing (subject to tweaking still but that's the gist of
it). These should be included in the next feature release, assuming no
issues pop up. Having some kind of explicit handling for array
containment seems like an interesting idea -- we'll have to give it some
thought.

Wyatt
>
> ---
> R.I.Pienaar
>


R.I.Pienaar

unread,
Jul 10, 2016, 7:41:15 PM7/10/16
to Wyatt Alt, puppet...@googlegroups.com

> On 11 Jul 2016, at 00:39, Wyatt Alt <wy...@puppet.com> wrote:
>
>
>
>
>> On 07/10/2016 01:32 PM, R.I.Pienaar wrote:
>> hey,
>>
>> Been playing with the PQL language and it's quite nice, have 2 questions.
>>
>> I want to do a regex case insensitive match, docs mention you can do whatever
>> Postgres supports but I can't figure out how to do case insensitive matches
>> with PQL?
>>
>> Postgres supports ~ and ~* operators but PQL only supports ~. So I suppose
>> I could match [aA][bB][cC] to get case insensitivity, but thats a tad ugly
> Hey R.I,
>
> I agree -- the docs are incorrect here and if you link the page you're looking at I'll change them. PuppetDB currently only supports postgres's ~ operator, but I think adding support for ~* would be a good feature and technically easy, so I've created https://tickets.puppetlabs.com/browse/PDB-2861 to address it. For now your hack is probably the best you can do.

Thanks. No if that's all you support the docs are correct. They mention it supports some marchers pgsql supports but I guess those are more related to the fact that it's the basic posix regex only and nothing fancy.

>>
>> Next I have a fact like:
>>
>> foo => { bar => ["a", "b", "c"]}
>>
>> How do I search into that where bar contains "b"? There's an "in" operator
>> but I can't seem figure out both how to search inside the sub hash and also
>> how to match inside a array like that?
> Querying structured facts in PQL is still pretty inconvenient in some cases, but you could do this with something like
>
> fact_contents{path ~> ["foo", "bar", "\\d"] and value = "b"}
>
> This can be inserted as a subquery to get the certnames associated with such a value, e.g
>
> nodes{certname in fact_contents[certname]{path ~> ["foo", "bar", "\\d"] and value = "b"}}
>
> Incidentally, we have two tickets in flight (PDB-2632 and PDB-2633) that will enable the nicer syntax
>
> inventory{facts.foo.bar.match("\\d") = "b"}
>
> to do the same thing (subject to tweaking still but that's the gist of it). These should be included in the next feature release, assuming no issues pop up. Having some kind of explicit handling for array containment seems like an interesting idea -- we'll have to give it some thought.

Right I think I can probably hack up what I need then with your suggestion. If I get it working I will open a docs ticket to get some examples added

Thanks! PQL is a lot easier than the other format :) though there was some pretty frustrating times since it got hung up spaces around () and {} I will find my broken queries and open tickets about those too

Oh and the "puppet query" tool doesn't seem to be linked against SSL so couldn't get it to speak over https

I will look in the week if there are existing tickets as open some. Just wanted to get my back working before going to deep in jira.


>
> Wyatt
>>
>> ---
>> R.I.Pienaar
>
>

Reply all
Reply to author
Forward
0 new messages