influxQL fuzzy query with "/" - influxdb

I have a InfluxQL to try to locate id include specific str. I think it is the "/" inside string that causes error
Anyone can help ?
Thanks
select * from Utility_3 where "id"=~/^"RealTime/NCU-05-01"/ limit 10
ERR: error parsing query: found NCU, expected ; at line 1, char 49

Related

Extract string values that are enclosed in slashes

An example url that I'm trying to collect the values from has this pattern:
https://int.soccerway.com/matches/2021/08/18/canada/canadian-championship/hfx-wanderers/blainville/3576866/
The searched value always starts at the seventh / and ends at the ninth /:
/canada/canadian-championship/
The method I know how to do is using LEFT + FIND and RIGHT + FIND, but it is very archaic, I believe there is a better method for this need.
Another alternative:
="/"&textjoin("/", 1, query(split(A1, "/"), "Select Col7, Col8"))&"/"
The searched value always starts at the seventh / and ends at the ninth /:
Here's another way you can do it:
="/"&regexextract(A1,"(?:.*?/){7}(.*?/.*?/)")
You can use =REGEXTRACT() to match part of the string with a regular expression:
For example, If A1 = https://int.soccerway.com/matches/2021/08/18/canada/canadian-championship/hfx-wanderers/blainville/3576866/ ,
then
=REGEXEXTRACT(A1, "\/[^\/]*\/[^\/]*\/[^\/]*\/[^\/]*\/[^\/]*\/[^\/]*(\/[^\/]*\/[^\/]*\/)")
returns
/canada/canadian-championship/
Explanation: \/ is '/' escaped. [^\/]* matches any non '/' character 0 or more times. \/[^\/]* is repeated 6 times. () captures a specific part of the string as a group to be returned. Finally (\/[^\/]*\/[^\/]*\/) matches the essential part we want.
Little bit different approach.
=REGEXEXTRACT(SUBSTITUTE(SUBSTITUTE(A1,"/","|",9),"/","|",7),"\|(.*?)\|")

Figuring out what this Trim() function is doing?

I have a constraint on a transformer with this:
Trim(CollectFrom.collect_from,"-","A")<=TheDate
Here is what collect_from looks like:
'2017-02-27'
And here is what TheDate looks like:
'20170227'
I am unsure exactly how this Trim() function works. My first guess is that it is giving it the same format as 'TheDate' however I don't understand the "A" argument. Could somebody explain it?
The manual page for TRIM() says that shouldn't work.
When I try to run what you show, I get errors:
SQL[2405]: select trim('2017-02-01', '-', 'A') from dual;
SQL -674: Routine (trim) can not be resolved.
SQLSTATE: IX000 at /dev/stdin:1
SQL[2406]: select trim('2017-02-01', '-') from dual;
SQL -674: Routine (trim) can not be resolved.
SQLSTATE: IX000 at /dev/stdin:2
The manual says you need TRIM({BOTH|LEADING|TRAILING} [char] FROM source):
SQL[2407]: select trim(both '-' from '2017-02-12') from dual;
2017-02-12
SQL[2408]: select trim(both '-' from '2017-02-12-') from dual;
2017-02-12
SQL[2409]: select trim(both '-' from '-2017-02-12-') from dual;
2017-02-12
SQL[2410]:
(The SQL command interpreter used is my SQLCMD.)
There's a chance that someone has defined a TRIM function that takes three arguments — that's not detectable from here. You'd have to look in the system catalog of your database to find that.
OTOH, that doesn't seem to be allowed, either:
SQL[2411]: create function trim(a varchar(10), b varchar(20), c varchar(30)) returning varchar(64);
return trim(leading from a) || ' ' || trim(both from b) || ' ' || trim(trailing from c);
end function;
SQL -9710: Overloading of built-in functions is not allowed.
SQLSTATE: IX000 at /dev/stdin:8
SQL[2412]:
Informix 11.50 has build in trim() function: https://www.ibm.com/support/knowledgecenter/SSGU8G_11.50.0/com.ibm.sqls.doc/ids_sqs_1556.htm But it looks little different from trim() in your question, so I think you use trim() function build by some user.
Normally trim() takes care only at chars at beginning or at end of the string, but in your example trim() had to remove - chars that are in the middle of the string. I guess that last argument A tells trim() to remove all such characters from source string.
To find out what trim() function really do you must find it source. You can do it with some GUI database tools like SQirreL SQL Client (it uses JDBC), you can do it with dbschema Informix utility or with my Python/Jython program that uses ODBC/JDBC: https://code.activestate.com/recipes/576621-dump-informix-schema-to-text
It would be helpful to tell us what version of Informix you use.
Trim(CollectFrom.collect_from,"-","A")
Here A means to Remove all the occurrences of '-' from the input string CollectFrom.collect_from . Hence You are getting '20170227' . Here is the document which would give further more information on Trim function.
https://www.ibm.com/support/knowledgecenter/en/SSZJPZ_11.5.0/com.ibm.swg.im.iis.ds.parjob.dev.doc/topics/r_deeref_String_Functions.html

Do not understand the error in Neo4j creation of nodes.

I am trying to create a node
create (n:node0{78 : 78});
This results in an error of
Invalid input ':': expected whitespace, comment or '}' (line 1, column 20 (offset: 19))
"create (n:node0{78 : 78})"
^
The book I am following "Learning Neo4j" by Bruggen, Packt Publishing.
My guess is that "78" cannot be a key name (most likely because it starts with a digit) and the correct code should be like
create (n:node0{param78: 78})

Execute immediate 'Create or replace view' gives 00900. 00000 - "invalid SQL statement" error

I have been stuck with this error. Can you please suggest what the mistake is in the code below? This is written inside a procedure that takes input for the variables. Thanks.
execute immediate 'Create or replace view '||p_viewname||' AS
select * from (
select NAME, CODETYPE, CODE
from HLIDEV_VIEWS.V_CONCEPT
WHERE HLIDEV_VIEWS.V_CONCEPT.CONCEPTTYPE = '''||p_concepttype||'''
)
pivot
(
max(code)
for codetype in ('||all_codetypes||')
)';
Update: Below is the error I am seeing.
EXEC "HLIDEV_VIEWS"."FinalCreatePOAView" ('POA_CONCEPT_TYPE','PresentOnAdmission')
Error report -
ORA-00911: invalid character
ORA-06512: at "HLIDEV_VIEWS.FinalCreatePOAView", line 39
ORA-06512: at line 1
00911. 00000 - "invalid character"
*Cause: identifiers may not start with any ASCII character other than
letters and numbers. $#_ are also allowed after the first
character. Identifiers enclosed by doublequotes may contain
any character other than a doublequote. Alternative quotes
(q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
Reference Manual.
*Action:
What you are trying to do is perfectly doable using execute immediate. You just have a syntax error somewhere or the table really doesn't exist.
Try writing the string you are building to DBMS_OUTPUT.PUT_LINE instead of sending it to EXECUTE IMMEDIATE. Then, try to run that string as a command in SQL*Plus. That should highlight the error.
FWIW, I don't have your objects in my database, but I wrote an EXECUTE IMMEDIATE with the same form as yours and it works fine in Oracle 11g2.
DECLARE
p_view_name VARCHAR2(61) := 'VXSMIMMCP.MATT_V';
p_region_code VARCHAR2(30) := 'R01';
p_all_port_codes VARCHAR2(400) := '''P01'',''P02'',''P03''';
BEGIN
EXECUTE IMMEDIATE
'Create or replace view '
|| p_view_name
|| ' AS select * from ( select REGION_CODE, account_number , port_code from APPS.XXCUS_ACCOUNTS WHERE APPS.XXCUS_ACCOUNTS.REGION_CODE = '''
|| p_region_code
|| ''' ) pivot ( min(account_number) for port_code in ('
|| p_all_port_codes
|| ') )' ;
END;
Thank you #MatthewMcPeak and #MahendarMahi for your inputs. Suddenly my code started working fine and it created the view the way I wanted. The only thing I did was, as #MahendarMahi suggested, I removed pivot and ran it to see the same error and then replaced pivot and the error was gone. I am sure there is no change in the code but anyhow it weirdly works now. Thank you again for your time.

Groovy: Read file and get every matching result back

I've tried the whole working day to do this, but I've not a result yet. So, what i wan't to do is this:
I have a textfile, bad formated, in this file are hunderts of textes like these:
2012-02-21 05:16:47,205 ERROR - No KPI mapping found for kpi 'stoerungbeheben_moduleaccess_triage_1',
I will find all Strings between ' and ' so that one result is: stoerungbeheben_moduleaccess_triage_1 and write it back to another .txt file
The text is different, sometimes the same.
I've tried with filterLine and pattern with regex but it doesn't work.
Could you give me a hint how I can do that?
Kind regards
Collin
The following groovy-script produces the desired result (though does not write to file, but I believe you can easily achieve that):
def regex = "[0-9]+-[^']+'([^']+)'[^\r\n]*\r?\n?"
def source = """
2012-02-21 05:16:47,205 ERROR - No KPI mapping found for kpi 'stoerungbeh_¤eben_moduleaccess_triage_1',
2012-02-21 05:16:47,205 ERROR - No KPI mapping found for kpi 'otherbeheben_üü'
2012-02-21 05:16:47,205 ERROR - No KPI mapping found for kpi 'stoerungbeheben_moduleaccess_triage_1',
2012-02-21 05:16:47,205 ERROR - No KPI mapping found for kpi 'thirdhbeheben_äÄ_moduleaccess_triage_1'
2012-02-21 05:16:47,205 ERROR - No KPI mapping found for kpi 'stoerungbeheben_mo&%duleaccess_triage_1',
"""
java.util.regex.Pattern p = java.util.regex.Pattern.compile(regex)
java.util.regex.Matcher m = p.matcher(source)
while(m.find()) {
println(m.group(1))
}
yields:
stoerungbeh_¤eben_moduleaccess_triage_1
otherbeheben_üü
stoerungbeheben_moduleaccess_triage_1
thirdhbeheben_äÄ_moduleaccess_triage_1
stoerungbeheben_mo&%duleaccess_triage_1
EDIT:
The explanation of the pattern would have been to long of a comment so added it to the answer:
Wikipedia article has a fairly comprehensive table of regex meta characters: http://en.wikipedia.org/wiki/Regular_expression#Examples
IMO the best way to learn and understand regexes is to write and execute zounds of regexes against various arbitrary strings.
The pattern is far from optimal but here's some explanation for [0-9]+-[^']+'([^']+)'[^\r\n]*\r?\n?:
[0-9]+- => + sign means match 1 or more numbers from 0 to 9. Then stop at hyphen (example: 2012-). This for tackling the case if there's no newline or it is the last line.
[^']+' => match 1 or more characters that are not apostrophe and stop at apostrophe (example: -02-21 05:16:47,205 ERROR - No KPI mapping found for kpi ').
([^']+)' => match and capture 1 or more characters that are not apostrophe and stop at apostrophe (example: stoerungbeheben_moduleaccess_triage_1' where from the captured part in brackets is: stoerungbeheben_moduleaccess_triage_1).
[^\r\n]* => match 0 or more characters that are not carriage return (\r) or newline (\n) (example: ,).
\r? => match carriage return if it exists.
\n? => match newline if it exists.

Resources