This message was deleted.
# general
s
This message was deleted.
v
how come there are
\
before the
"
around test? in what you posted? Are yo submitting the string from something that does its own escaping?
you are correct that the docs should call out that str2 is a regexp
@Charles Smith (FYI)
☑️ 1
Do you have an extra layer of escaping on top of Druid? Can you double check your query in the console as a baseline?
Ok docs have been updated to indicate the regex
👍 1
j
To answer your question, it's part of the ingestion spec (transform).
v
Ah... well you see what is happening here is that you are not using SQL (as I first assumed you were) the transform spec uses a lower lever expression language called math-expr (https://druid.apache.org/docs/latest/misc/math-expr.html). In math-expr you have to escape
\
in literals (unlike in SQL). So to encode the regex
\|
you have to have
'\\|'
as the second argument to
string_to_array
. But that whole thing is contained within a JSON string representing the ingestion spec... so you need to express
string_to_array("test", '\\|')
in the json you actually have to write
"string_to_array(\"test\", '\\\\|')"
. I hope this answers your question of why the delimiter is going through multiple stages of interpolation. It is intended.
Now what can you do about it?
1) if you are using batch ingestion you can switch to SQL based ingestion which has less escaping due to the way SQL escaping is done as you saw above
j
Interesting. Are all string literals interpolated in math-expr?
v
2) you can avoid using the
\
character and use the fact that math-expr allows you to enter unicode code points . os write
\u005C
which will be
"...\\u005C..."
when written inside of a JSON string
that is in fact what the Druid SQL planner does when it generates the internal JSON based query
🍺 1
Although I don't know if that is more readable
I am not sure what you mean by "string literals interpolated"
j
Well,
'\\|'
is a string literal and it's clearly being interpolated. I didn't know you could use Unicode code points, for instance. That must be why it is interpolated.
v
btw I am no expert on math-expr. In fact I detest writing it... whenever I need to write a math-expr (like in the process of answering this inquiry) I always write a SQL query and then do explain plan in the console and copy out the expression I need from the plan.
🍺 1
j
Oh that's a neat tip.
v
hm... in my vocabulary interpolation in the context of strings means inlining expressions into string literals (instead of concatenating many fragments together). Like in JavaSscript you can do
Copy code
console.log(`Hello ${firstName}, the time right now is ${new Date()}`);
to my knowledge you can not do ☝️ in math-expr.
j
Good point. I'm unsure what to call it when a string goes through a transformation that requires an escape sequence to overcome other than string interpolation. But Druid string literals only supports specific escape sequences and not "full interpolation".