In Exp,for one port(datatype:string) I have to check 8 different conditions.How Can i do it?
Thanks in Advance.
Depending on the requirements, either:
use one IIF statement connecting all your conditions with AND
use DECODE function if only one of the conditions will be met (it lets you avoid the nested IIFs)
Related
It's is possible to do a insert on a mapplet without SQL transformation? Like in an expression?
Thanks
The short answer is ‘no’
A mapplet cannot contain a target, it CAN contain a source, which is kind of counter intuitive I suppose :)
You must always have at least one port going out of the mapplet, but as you suggest, it is possible to do ‘writing’ anyway, using a sql-trans.
Personally I prefer not to do so, and let all the writing happen immediately after the mapplet, since the sql trans is rather difficult to debug, and logging metadata in the repository is non-existing.
I am new to XQuery and MarkLogic.
I am trying to update documents in MarkLogic and get the extended tree cache full error.
Just to get the work done I have increased the expanded tree cache but that is not recommended.
I would like to tune this query so that it does not need to simultaneously cache as much XML.
Here is my query
I have uploaded my query as an image because it was not so pretty when I pasted it on the editor. If any one knows a better way please suggest.
Thanks in advance.
Expanded tree cache errors can be caused by executing queries that select too many XML nodes at once. In your example, this is likely the culprit: /tx:AttVal[tx:AttributeName/text()=$attributeName].
It's possible that calling text() is the source of your problem (and text() probably not what you mean anyway - see this blog), causing MarkLogic to evaluate that function on all these nodes, and that by simply using /tx:AttVal[tx:AttributeName=$attributeName] it may solve your problem.
Next I would consider an adding a path range index on /tx:AttVal/tx:AttributeName and query those nodes using cts:search and cts:path-range-query. This will be substantially faster than just XPath without a range index. It's also possible to use XPath with a range index: MarkLogic will automatically optimize the XPath expression to use the range index; however, there can be reasons it doesn't optimize the expression correctly, and you would want to check that using xdmp:plan.
Also note that the general best practice recommendation for XML in MarkLogic is to use "semantic XML". E.g., when you mean an attribute, use an attribute: <some-node AttributeName=AttVal>. MarkLogic's indexes are optimized out of the box for semantic XML design. However, if you don't have an option but to work with XML that's not, then that's what path range indexes were designed for.
I've just solved exactly this scenario. There are two things I did
I put the node-replace and node-insert type calls (that is any calls that modify the XML structure into a separate module and then called that module using xdmp:invoke, passing in any parameters required, like this
let $update := xdmp:invoke("/app/lib/update-attribute-node.xqy",
(xs:QName("newValue"), $new),
{xdmp:modules-database()})
The reason why this works is that the call to xdmp:invoke happens in it's own transaction and once it completes, the memory is cleared up. If you don't do this then, each time you call the update or insert function, it will not actually do the write, until the end in a single transaction meaning your memory will fill up pretty quickly.
Any time I needed to loop over paths in MarkLogic (or documents or whatever they are called - I've only been using MarkLogic for a few days) and there are a large number of them I processed them only a few at a time like below. I came up with an elaborate way of skipping and taking only a batch of documents at a time, but you can do it in any number of ways.
let $whatever:= xdmp:directory("/whatever/")[$start to $end]
I also put this into a separate module so that it is processed immediately and not in a single transaction.
Putting all expensive calls into separate modules and taking only a subset of large data sets at a time helped me solve my expanded tree cache full errors.
I'm revising a data step that resides in a SAS macro. Currently a single format is used to create a new field for the whole dataset. I'm attempting to revise it to where a different format will be used on different subsets of the dataset. (I have a field that indicates which subset the row belongs to.)
I could do this with a bunch of if statements, but that would need to be changed if the number of categories changes in the future. I think I can achieve what I want by using call symput and resolve but I'm unsure what the syntax for that would be. Can I achieve this without resorting to if statements?
Your question isn't perfectly clear, but if you want to do something like
newvar = put(oldvar,MYFMT.)
->
if x=1 then newvar=put(oldvar,MYFMT.);
else newvar=put(oldvar,MYFMT2.);
But without all of the if statements, you can use PUTN or PUTC, which allows you to specify the format at runtime.
newvar = putn(oldvar,fmtvar); *optionally can specify w and d as separate arguments also;
%Examples
%course_meetings(maths4,tutorial,t07,khaled_mohamed,'tutorial for t07')
%days([sat,sun...])
%tutorialrooms([c6301,b4108,c2201,c2301,c2202,c2203])
%slots([1,2,3,4,5])
day_tut(Day,Slot,Place,Course,Group,Instr,Descr):-
days(X),member(Day,X),
tutorialrooms(X1),member(Place,X1),
course_meetings(Course,tutorial,Group,Instr,Descr),
slots(X2),member(Slot,X2).
I thought of using Assert but I am new to prolog not sure how it works the idea is that eventually I would like to create a schedule for all groups according to certain rules example each group should have a day off and lectures should preceed tutorials ...
My suggestions are coming from SWI-Prolog.
You can insert data to a dynamic database using assert/1; you can put the tuple on the Linda table with out/1 or use even more advanced features such as db_assert.
The question is, however, not HOW to record this data but rather WHY do you want to do it. Depending on how do you intend to address the scheduling problem you might need this recording strategy or that, or may be even none.
I'm currently working with JMeter in order to stress test one of our systems before release. Through this, I need to simulate users clicking links on the webpage presented to them. I've decided to extract theese links with an XPath Post-Processor.
Here's my problem:
I have an a XPath expression that looks something like this:
//div[#data-attrib="foo"]//a//#href
However I need to extract a specific child for each thread (user). I want to do something like this:
//div[#data-attrib="foo"]//a[position()=n]//#href
(n being the current index)
My question:
Is there a way to make this query work, so that I'm able to extract a new index of the expression for each thread?
Also, as I mentioned, I'm using JMeter. JMeter creates a variable for each of the resulting nodes, of an XPath query. However it names them as "VarName_n", and doesn't store them as a traditional array. Does anyone know how I can dynamicaly pick one of theese variables, if possible? This would also solve my problem.
Thanks in advance :)
EDIT:
Nested variables are apparently not supported, so in order to dynamically refer to variables that are named "VarName_1", VarName_2" and so forth, this can be used:
${__BeanShell(vars.get("VarName_${n}"))}
Where "n" is an integer. So if n == 1, this will get the value of the variable named "VarName_1".
If the "n" integer changes during a single thread, the ForEach controller is designed specifically for this purpose.
For the first question -- use:
(//div[#data-attrib="foo"]//a)[position()=$n]/#href
where $n must be substituted with a specific integer.
Here we also assume that //div[#data-attrib="foo"] selects a single div element.
Do note that the XPath pseudo-operator // typically result in very slow evaluation (a complete sub-tree is searched) and also in other confusing problems ( this is why the brackets are needed in the above expression).
It is recommended to avoid using // whenever the structure of the document is known and a complete, concrete path can be specified.
As for the second question, it is not clear. Please, provide an example.