https://pinot.apache.org/ logo
n

Nick Bowles

02/10/2021, 10:31 PM
Hey team thanks for setting this slack up! Would appreciate any help on this: I’m trying to do a multi line groovy script like this in a query in the Pinot Query Console:
Copy code
""" 
def value = 'blah'
return value
"""
using this syntax:
Copy code
select groovy('{"returnType":"STRING","isSingleValue":true}', <GROOVY MULTI LINE HERE>, my_variable) as new_variable from table
I have tried to cancel out the quotes, use single, cancel any newlines, and cannot figure out how to get this to work. Any ideas?
n

Neha Pawar

02/10/2021, 10:34 PM
Copy code
select 
groovy(
  '{"returnType":"DOUBLE","isSingleValue":true}'
  'def sumSales=0; 
  arg0.eachWithIndex{item, index-> if (item != "mug") 
    {sumSales = sumSales + arg1[index]}}; return sumSales' , 
    p1, p2) 
from fooTable 
limit 10
here’s a multi line groovy script that used to work for me
n

Nick Bowles

02/10/2021, 11:01 PM
Tried in that format and I get this every time
Copy code
select
groovy(
  '{"returnType":"STRING","isSingleValue":true}',
	'def var=1;
	 return var') as myvar
from table limit 10
Running this returns the same result of the 200 error code.
n

Neha Pawar

02/10/2021, 11:04 PM
since you’ve specified return type STRING, you’d have to use
def var="1"
this works for me
select groovy('{"returnType":"STRING","isSingleValue":true}','def var="1"; return var') from foo limit 10
n

Nick Bowles

02/10/2021, 11:10 PM
Sorry that was a bad copy paste. I had INT originally. If I paste what you put in and change the table it runs, but if I paste mine it doesn’t…guessing something is happening with the characters when I’m pasting from my text editor
This works
This doesn’t
all I did for the second one was hit enter to put it on the next line.
Using triple quotes doesn’t work. Cancelling the newline doesn’t work
I’ve also tried iterations of using triple single quotes, triple gstring quotes, can’t get anything to work
n

Neha Pawar

02/10/2021, 11:30 PM
why does it need to be on the next line?
n

Nick Bowles

02/10/2021, 11:31 PM
readability, i’ve got some conditionals and other stuff in there so it won’t be pretty on one line 🙂
I’m guessing there’s got to be a way to cancel that newline out if that’s causing the issue. Thanks for your help by the way!