qlikview MapSubString - qlikview

I am using mapping load with MapSubString but it doesnt work for searching the sentence start and ends with text.
For example : All below cases will be mapped with Network fault.
Network Element fault
Network Radio equipment fault
Network had some unknown fault
So the search must be something like Network*fault
I cannot make it with wildmatch because i have around 280 keywords to be searched.
Thanks in advance
Keywords:
Mapping load Upper(Keyword) as Keyword, '$' &Todo& '~' as Todo
FROM [$(ROOTPATH)\Config\projects\$(vPROJECTNAME)\Ticket_Defect_Keyword.xlsx]
(ooxml, embedded labels, table is Sheet1);
load ticket_id, TextBetween(MapSubString('Keywords', Upper(Remark&'-'&Failure_Detail)), '$', '~') as Keyword_Data
FROM F_TICKET

You mapping load is including '$' and '~':
'$' &Todo& '~'
but TextBetween will not include them. It will just select text between them, excluding '$' and '~'.
So for sure you need to remove '$' and '~' from mapping load:
Keywords:
Mapping load
Upper(Keyword) as Keyword,
Todo
FROM
[$(ROOTPATH)\Config\projects\$(vPROJECTNAME)\Ticket_Defect_Keyword.xlsx]
(ooxml, embedded labels, table is Sheet1);
load
ticket_id,
TextBetween(
MapSubString('Keywords', Upper(Remark&'-'&Failure_Detail))
, '$', '~') as Keyword_Data
FROM
F_TICKET

Related

ANTLR4 Correctly continuing to parse sections after error

I'm trying to write some tooling (validation/possibly autocomplete) for a SQL-esk query language. However, parser is tokenizing invalid/incomplete inputs in a way that is making it more difficult to work with.
I've reduce my scenario to its simplest reproducible form. Here is my minimized grammar:
grammar SOQL;
WHITE_SPACE : ( ' '|'\r'|'\t'|'\n' ) -> channel(HIDDEN) ;
FROM : 'FROM' ;
SELECT : 'SELECT' ;
/********** SYMBOLS **********/
COMMA : ',' ;
ID: ( 'A'..'Z' | 'a'..'z' | '_' | '$') ( 'A'..'Z' | 'a'..'z' | '_' | '$' | '0'..'9' )* ;
soql_query: select_clause from_clause;
select_clause: SELECT field ( COMMA field )*;
from_clause: FROM table;
field : ID;
table : ID;
When I run the following code (using antlr4ts, but it should be similar to any other port):
const input = 'SELECT ID, Name, Website, Contact, FROM Account'; //invalid trailing ,
let inputStream = new ANTLRInputStream(input);
let lexer = new SOQLLexer(inputStream);
let tokenStream = new CommonTokenStream(lexer);
let parser = new SOQLParser(tokenStream);
let qry = parser.soql_query();
let select = qry.select_clause();
console.log('FIELDS: ', select.field().map(field => field.text));
console.log('FROM: ', qry.from_clause().text);
Console Log
line 1:35 extraneous input 'FROM' expecting ID
line 1:47 mismatched input '<EOF>' expecting 'FROM'
FIELDS: Array(5) ["ID", "Name", "Website", "Contact", "FROMAccount"]
FROM:
I get errors (which is expected), but I was hoping it would still be able to correctly pick out the FROM clause.
It was my understanding since FROM is a identifier, it's not a valid field in the select_clause (maybe I'm just misunderstanding)?
Is there some way to setup the grammar or parser so that it will continue on to properly identify the FROM clause in this scenario (and other common WIP query states).
It was my understanding since FROM is a identifier, it's not a valid
field in the select_clause (maybe I'm just misunderstanding)?
All the parser sees is a discrete stream of typed tokens coming from the lexer. The parser has no intrinsic way to tell if a token is intended to be an identifier, or for that matter, have any particular semantic nature.
In designing a fault-tolerant grammar, plan the parser to be fairly permissive to syntax errors and expect to use several tree-walkers to progressively identify and where possible resolve the syntax and semantic ambiguities.
Two ANTLR features particularly useful to this end include:
1) implement a lexer TokenFactory and custom token, typically extending CommonToken. The custom token provides a convenient space for flags and logic for identifying the correct syntactic/semantic use and expected context for a particular token instance.
2) implement a parser error strategy, extending or expanding on the DefaultErrorStrategy. The error strategy will allow modest modifications to the parser operation on the token stream when an attempted match results in a recognition error. If the error cannot be fully resolved and appropriately fixed upon examining the surrounding (custom) tokens, at least those same custom tokens can be suitably annotated to ease problem resolution during the subsequent tree-walks.

Django Concat columns with integers and strings

I have run into an issue using attempting to add values from two different columns together in a query, namely that some of them contain numbers. This means that the built in Concat does not work as it requires strings or chars.
Considering how one can cast variables as other datatypes in SQL I don't see why I wouldn't be able to do that in Django.
cast(name as varchar(100))
I would assume that one would do it as follows in Django using the Concat function in combination with Cast.
queryset.annotate(new_col=Concat('existing_text_col', Cast('existing_integer_col', TextField())).get())
The above obviously does not work, so does anyone know how to actually do this?
The use case if anyone wonders are sending jenkins urls saved as fragments as a whole. So one url would be:
base_url: www.something.com/
url_fragment: name/
url_number: 123456
I ended up writing a serializer that inherits from the base serializer that contains the urls fragments and a lot of other things. In it I made a MethodField for my complete url and defined a getter function that loaded in the different fragments and added them together. I also redeclared the fragmented fields to None.
The code inside the new serializer is:
complete = serpy.MethodField("get_copmlete")
serverUrl = serpy.Field(attr=None, call=False, required=False)
jobName = serpy.Field(attr=None, call=False, required=False)
buildNumber = serpy.Field(attr=None, call=False, required=False)
def get_complete(self, obj):
return obj.server_url + obj.job_name + '/' + str(obj.build_number)

FOR XML could not serialize the data for node because it contains a character (0x000E)

I am trying to use FOR XML in SSRS, but when the report runs it sometimes gives me this error:
FOR XML could not serialize the data for node 'NoName' because it contains a character (0x000E) which is not allowed in XML. To retrieve this data using FOR XML, convert it to binary, varbinary or image data type and use the BINARY BASE64 directive.
I'm using FOR XML to concatenate a comments column into one cell within SSRS. Since multiple comments can exist for one user, this would solve the issue with duplicates. Does anyone have an idea why I would get this error in SSRS?
It appears to be a special character that looks like a musical note. You can find the row that is causing your problem like this:
SELECT Notes FROM MyTable WHERE Notes like '%' + char(0x000E) + '%'
You can fix the problem by removing the offending character.
UPDATE MyTable SET Notes = REPLACE(Notes, char(0x000E) , '')
WHERE Notes like '%' + char(0x000E) + '%'

Having greater than or less than in hibernate named sql query

I'm using hibernate 3 with named query in the hibernate configuration xml.
The named query originally matched a date with the user entered date, and it worked fine.
But when I changed the equals ('=') to a less than ('<=') it gave me the following error.
Caused by: org.hibernate.MappingException: Could not parse mapping document in input stream
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:431)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)
... 106 more
Caused by: org.dom4j.DocumentException: Error on line 57 of document : The content of elements must consist of well-formed character data or markup. Nested exception: The content of elements must consist of well-formed character data or markup.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:422)
... 107 more
This is because the XML parser does not allow '<' or '>' inside the content of tags. But '<' or '>' is necessary to form the <= or >= comparison. Is there an alternate way to represent greater than or less than such that the parser is happy.
NB: I already know we can put the named query as annotation in the code, but I prefer it this way for system consistency.
Sample Named Query:
<sql-query name="persons">
<return alias="person" class="eg.Person"/>
SELECT person.NAME AS {person.name},
person.AGE AS {person.age},
person.SEX AS {person.sex}
FROM PERSON person
WHERE person.NAME LIKE :namePattern
AND trim(person.JOINDATE) <= to_date(:joinDate, 'dd-mm-yyyy')
</sql-query>
Use CDATA or < to escape < in xml.

How to preserve an ampersand (&) while using FOR XML PATH on SQL 2005

Are there any tricks for preventing SQL Server from entitizing chars like &, <, and >? I'm trying to output a URL in my XML file but SQL wants to replace any '&' with '&'
Take the following query:
SELECT 'http://foosite.com/' + RTRIM(li.imageStore)
+ '/ImageStore.dll?id=' + RTRIM(li.imageID)
+ '&raw=1&rev=' + RTRIM(li.imageVersion) AS imageUrl
FROM ListingImages li
FOR XML PATH ('image'), ROOT ('images'), TYPE
The output I get is like this (&s are entitized):
<images>
<image>
<imageUrl>http://foosite.com/pics4/ImageStore.dll?id=7E92BA08829F6847&raw=1&rev=0</imageUrl>
</image>
</images>
What I'd like is this (&s are not entitized):
<images>
<image>
<imageUrl>http://foosite.com/pics4/ImageStore.dll?id=7E92BA08829F6847&raw=1&rev=0</imageUrl>
</image>
</images>
How does one prevent SQL server from entitizing the '&'s into '&'?
There are situations where a person may not want well formed XML - the one I (and perhaps the original poster) encountered was using the For XML Path technique to return a single field list of 'child' items via a recursive query. More information on this technique is here (specifically in the 'The blackbox XML methods' section):
Concatenating Row Values in Transact-SQL
For my situation, seeing 'H&E' (a pathology stain) transformed into 'well formed XML' was a real disappointment. Fortunately, I found a solution... the following page helped me solve this issue relatively easily and without having re-architect my recursive query or add additional parsing at the presentation level (for this as well for as other/future situations where my child-rows data fields contain reserved XML characters): Handling Special Characters with FOR XML PATH
EDIT: code below from the referenced blog post.
select
stuff(
(select ', <' + name + '>'
from sys.databases
where database_id > 4
order by name
for xml path(''), root('MyString'), type
).value('/MyString[1]','varchar(max)')
, 1, 2, '') as namelist;
What SQL Server generates is correct. What you expect to see is not well-formed XML. The reason is that & character signifies the start of an entity reference, such as &. See the XML specification for more information.
When your XML parser parses this string out of XML, it will understand the & entity references and return the text back in the form you want. So the internal format in the XML file should not cause a problem to you unless you're using a buggy XML parser, or trying to parse it manually (in which case your current parser code is effectively buggy at the moment with respect to the XML specification).
Try this....
select
stuff(
(select ', <' + name + '>'
from sys.databases
where database_id > 4
order by name
for xml path(''), root('MyString'), type
).value('/MyString[1]','varchar(max)')
, 1, 2, '') as namelist;