Multiple if else in gremlin query - graph

Data Model is as follows:
g.addV('A').property('property1',0).property('input','two').next()
g.addV('B').property('property2',0).next()
g.V().has('property1',0).as('fromV').V().has('property2',0).as('toV').addE('AB').from('fromV').to('toV').iterate()
First, need to check whether the node A and B are connected by AB relation. If yes, change the property value for node A according to the given input.
Condition for property value:
if input="one" then 1
else if input="two" then 2
else if input="three" then 3
else 0
Tried the following query:
g.V().has('property1',0).where(outE('AB').inV('B')).property('property1',choose(values('input').is(eq('one')),1,choose(values('input').is(eq('two')),2,choose(values('input').is(eq('three')),3,0))))
Error:
No signature of method: static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.choose() is applicable for argument types: (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal...) values: [[PropertiesStep([input_currency],value), IsStep(eq(Local))], ...]
Possible solutions: choose(java.util.function.Function), choose(org.apache.tinkerpop.gremlin.process.traversal.Traversal), choose(java.util.function.Predicate, org.apache.tinkerpop.gremlin.process.traversal.Traversal), choose(org.apache.tinkerpop.gremlin.process.traversal.Traversal, org.apache.tinkerpop.gremlin.process.traversal.Traversal), choose(java.util.function.Predicate, org.apache.tinkerpop.gremlin.process.traversal.Traversal, org.apache.tinkerpop.gremlin.process.traversal.Traversal), choose(org.apache.tinkerpop.gremlin.process.traversal.Traversal, org.apache.tinkerpop.gremlin.process.traversal.Traversal, org.apache.tinkerpop.gremlin.process.traversal.Traversal)
Type ':help' or ':h' for help.
Display stack trace? [yN]

using option solves the problem.
Query:
g.V().has('property1',0).where(outE('AB').inV('B')).property('property1',choose(values('input')).option('one',1).option('two',2).option('three',3))

Related

MDX error trying to compare one hierarchy level to another one

I have an MDX issue that I really don't understand with a 5 level hierarchy "SEGMENTATION" : AFFAIRE/NIVEAU 1/ NIVEAU 2/NIVEAU 3/NIVEAU 4
I want to compare "NIVEAU 1" sub-levels weight to "Niveau 1".
For instance, I want to know for each 'NIVEAU 3' members its contributions part for its "NIVEAU 1".
I've tried a bunch of things, but nothing works properly. I don't get the trick and is stucked to :
WITH MEMBER [Measures].[TEST] AS'
iif(ISEMPTY(([Segmentation].[Niveau1], [Measures].[Total])) OR ([Segmentation].[Niveau1],[Measures].[Total]) = 0
, NULL
,[Measures].[Total] / ([Segmentation].[Niveau1], [Measures].[Total])
)'
SELECT NON EMPTY { [Measures].[TEST],[Measures].[Total]} ON COLUMNS
, NON EMPTY { [Segmentation].[Niveau2]}
ON ROWS FROM ( SELECT ( { [Segmentation].[Niveau1].&[8589934592]&[1|DESC111] } ) ON COLUMNS FROM [CUBE]) // Only one "Niveau 1" focus
And I get :
<Niveau 2> TEST Total
SF - C... #Error 25143658
SF - M... #Error 1638913,5
ZZZ ... #Error 90468628
#Error : The EqualTo function expects a string or numeric expression for argument 1. A tuple set expression was used.
The expected result is :
<Niveau 2> TEST Total
SF - C... 21,44% 25143658
SF - M... 1,40% 1638913,5
ZZZ ... 77,16% 90468628
21,4% = 25143658/(25143658+1638913,5+90468628)
What's wrong with my MDX?
Is there a mistake among the dimension or hierarchy set up?
Tuples are written as comma separated lists of members. What you have is a dimension.
Try
[Segmentation].CurrentMember.Parent
Instead of
[Segmentation].[Niveau1]
On your measure definition.
[EDIT] As mentioned in a comment, the goal is a solution that works on all levels. The solution is to use
Ancestor( [Segmentation].CurrentMember, [Segmentation].[Niveau1] )
in the Tuple used in the custom measure definition.
Thanks to nsousa, I'm now using :
WITH MEMBER [Measures].[Total Niveau1] AS'
iif([Segmentation].CURRENTMEMBER.level.ordinal>=2
,(Ancestor([Segmentation].CurrentMember,[Segmentation].[Niveau1] ),[Measures].[Total])
,([Segmentation].CURRENTMEMBER, [Measures].[Total])
)
'
MEMBER [Measures].[TEST] AS'
DIVIDE([Measures].[Societe],[Measures].[Total Niveau1])
',FORMAT_STRING = 'Percent'
SELECT NON EMPTY { [Measures].[TEST],[Measures].[Societe],[Measures].[Total]} ON COLUMNS
, NON EMPTY { [Segmentation].[Niveau3]}
ON ROWS FROM [CUBE]

Finding the most frequent terms in an index (Error: 400 - all shards failed)

I indexed over 2.000.000 documents in Elasticsearch (using the library Elastic in R), I want to know the most frequent terms in a particular field, let say, the field is called 'X', containing strings. However, the aggregation function throws an error: Error: 400 - all shards failed
I tried the following in R (examples adjusted from the elastic library manual).
Step 1
I firstly created the index, with mapping (i.e., in the original index the 'X' field was indexed as 'keyword' field instead of text', I thought maybe that is the problem.
body <- list(test = list(properties = list(
X = list(type="text"),
Y = list(type="long")
)))
if (!index_exists("example")) index_create("example")
mapping_create(index = "example", type = "test", body=body)
Step 2
I next indexed a bunch of documents
X <- c("xxx first","xxx second","xxx third","yyy fourth")
Y <- c("21","22","24","17")
data <- data.frame(X,Y)
docs_bulk(x=data,index='example',type = "test")
Step 3
I next created the aggregation query and executed it in r
body <-
'{
"size": 0,
"aggs": {
"frequent_tags": {
"terms": {"field": "X"}
}
}
}
'
Search(index='example',body=body)
Step 4
... and I received the error "Error: 400 - all shards failed"
Step 5 and 6
Next I added "attribute." to the the body (i.e. {"field": "attribute.X"}), now the query is executed, but without any results. I also tried {"field": "keyword.X"}), but that did not give the expected results either.
Expected result
An object that says
xxx --> 3 documents
yyy --> 1 document
first --> 1 document
second --> 1 document
fourth --> 1 document
Thank you for your help; let me know if you need more info.
elastic maintainer here: first thing when trying to sort out problems on the Elasticsearch side is to do connect(errors = "complete") - which will throw the complete Elasticsearch stack trace in your R console when there is one. That should let you know exactly where the problem in your query is.
I followed your example above, with connect(errors = "complete") set, and I get:
Search(index='example',body=body)
Error: 400 - all shards failed
ES stack trace:
type: illegal_argument_exception
reason: Fielddata is disabled on text fields by default. Set fielddata=true on
[X] in order to load fielddata in memory by uninverting the inverted index.
Note that this can however use significant memory. Alternatively use a keyword
field instead.
with
elastic::ping()$version$number
[1] "6.6.1"

BMC Remedy ticket status change error in asp net

I'm using MVC to manage the BMC ticket raise and resolve. However for certain groups there are additional fields that opens up after choosing the type of change as 'Resolved'
I tried input values to those fields but still I'm not able to resolve the incident.
Below is the code used,
StagingRequest.Incident_Nature = "NA";
StagingRequest.Network_Infrastructure = "NA";
StagingRequest.Incident_Element = "NA";
String ss = _WS1.HelpDesk_Modify(_AI1, StagingRequest.Incident_Number, StagingRequest.Type_of_Change, StagingRequest.Status_Reason, StagingRequest.Group_Name, StagingRequest.Assignee_Login_ID, StagingRequest.Resolution, StagingRequest.Incident_Nature, StagingRequest.Network_Infrastructure, StagingRequest.Incident_Element, StagingRequest.WorkLog_SupportDiary, StagingRequest.Work_Info_Notes, StagingRequest.Expiry_Date);
Note that I tried entering the actual dropdown values in those 3 fields still the same error "Unable to Modify :ERROR (100000308): ; Please choose the value for the following fields before resolving the ticket; 'Incident Nature', 'Network Infrastructure' and 'Incident Element'. "
The other groups for which additional fields is not required worked with the below code,
String ss = _WS1.HelpDesk_Modify(_AI1, StagingRequest.Incident_Number, StagingRequest.Type_of_Change, StagingRequest.Status_Reason, StagingRequest.Group_Name, StagingRequest.Assignee_Login_ID, StagingRequest.Resolution, null, StagingRequest.Cause_for_SLA_Violation, StagingRequest.SLA_Comments, StagingRequest.WorkLog_SupportDiary, StagingRequest.Work_Info_Notes, StagingRequest.Expiry_Date);
Analysis the the difference in group in Remedy. Some groups are differently customized in remedy while resolving the incidents

add keys together in a dictionary

Hei guys! I need help in a python program. I wanna make a method which returns the sum of the keys as a dictionary. But I get a error "object is not iterable".
def totaltAntallSalg (dic) :
s = sum (dic.keys)
return s
call_function = totaltAntallSalg({"Ahmed":2,"Nada":1, "hala":3 })
How can I solve this problem?
thanks in advance
How can you add strings ? It might be values that you want to add.
To add values you may use following code:-
def totaltAntallSalg(dic):
D={}
D['sum']=sum(dic.values())
return D

MDX - distinct count

I was following this article:
http://msdn.microsoft.com/en-us/library/aa902637%28v=sql.80%29.aspx
and my query for distinct count looks like this:
Count(CrossJoin({[Measures].[Submission Count]}, [Submission].[PK Submission].Members), ExcludeEmpty)
it returns always 1 more than it should (for example it returns 27 instead of 26).
In the same article there is this query (which is suppose to solve this problem):
Count(CrossJoin( {[Sales]},
Descendants([Customers].CurrentMember, [Customer Names])),
ExcludeEmpty)
But I can't get it to work. I've tried these two but second one always returns 1 or 0 while the first one doesn't work (error: I have to explicitly define a level):
Count(CrossJoin( {[Measures].[Submission Count]},
Descendants([Submission].CurrentMember, [Submission].[PK Submission])),
ExcludeEmpty)
Count(CrossJoin( {[Measures].[Submission Count]},
Descendants([Submission].[PK Submission].CurrentMember, [Submission].[PK Submission])),
ExcludeEmpty)
Any idea what am I doing wrong?
Thanks!
The reason the first query returns "1 more than it should" is because the [Submission].[PK Submission].Members tuple set also includes the All member.
If you refer to the [PK Submission] level instead of all the members of the [PK Submission] hierarchy, it doesn't include the All member.
So, the following returns what you're expecting:
Count( CrossJoin( { [Measures].[Submission Count] }
, { [Submission].[PK Submission].[PK Submission] })
, ExcludeEmpty)

Resources