How to get schema of a vertex label gremlin using graph.OpenManagement() - gremlin

i' have created label schema using graph.OpenManagement() as described in https://docs.janusgraph.org/basics/schema/#schema-constraints
mgmt = graph.openManagement()
person = mgmt.makeVertexLabel('person').make()
name = mgmt.makePropertyKey('name').dataType(String.class).cardinality(Cardinality.SET).make()
birthDate = mgmt.makePropertyKey('birthDate').dataType(Long.class).cardinality(Cardinality.SINGLE).make()
mgmt.addProperties(person, name, birthDate)
mgmt.commit()
How can I get the person label schema. What is the gremlin query to get the properties list along with the datatype and cardinality info for a label.
Im using the following query to get the properties list with the data type, but there is no map for property to the label
gremlin> mgmt.printPropertyKeys()
==>------------------------------------------------------------------------------------------------
Property Key Name | Cardinality | Data Type |
---------------------------------------------------------------------------------------------------
name2 | SINGLE | class java.lang.String |
age2 | SINGLE | class java.lang.Integer |
name3 | SET | class java.lang.String |
birthDate3 | SINGLE | class java.lang.Long |
name4 | SET | class java.lang.String |
birthDate4 | SINGLE | class java.lang.Long |
name6 | SINGLE | class java.lang.String |
age6 | SINGLE | class java.lang.Integer |
name5 | SINGLE | class java.lang.String |
age5 | SINGLE | class java.lang.Integer |
mean_radius | SINGLE | class java.lang.Integer |
distance_in_kms | SINGLE | class java.lang.Integer |
new_field | SINGLE | class java.lang.String |
radius_in_kms | SINGLE | class java.lang.Integer |
name | SINGLE | class java.lang.String |
---------------------------------------------------------------------------------------------------

Getting vertex labels and their basic information:
mgmt.getVertexLabels().forEach(vertexLabel -> {
System.out.println("Vertex label: "+vertexLabel.name()+" isPartitioned: "+vertexLabel.isPartitioned()+" isStatic: "+vertexLabel.isStatic());
});
Getting edge labels and their basic information:
mgmt.getRelationTypes(EdgeLabel.class).forEach(edgeLabel ->{
System.out.println("Edge label: "+edgeLabel.name()+" Multiplicity: "+edgeLabel.multiplicity().name()+" isUnidirected:"+edgeLabel.isUnidirected());
});
Getting properties and their basic information:
mgmt.getRelationTypes(PropertyKey.class).forEach(propertyKey -> {
System.out.println("Property key: "+propertyKey.name()+" Cardinality: "+propertyKey.cardinality().name()+" Datatype: "+propertyKey.dataType().getName());
});
Now, when you got a specific Vertex label or a specific Edge label (as shown above), you can ask for the schema constraints information as shown below. Same methods are available for both VertexLabel and EdgeLabel.
Getting vertex label properties:
VertexLabel vertexLabel = mgmt.getVertexLabel("myVertexLabel");
vertexLabel.mappedProperties().forEach(propertyKey -> {
// get information about `propertyKey` as shown above in `Getting properties and their basic information` section
});
Getting vertex label connections:
VertexLabel vertexLabel = mgmt.getVertexLabel("myVertexLabel");
vertexLabel.mappedConnections().forEach(connection -> {
// connection.getEdgeLabel() - return the label of the edge. You can use it to access the edge itself if needed like:
EdgeLabel edgeLabel = mgmt.getEdgeLabel(connection.getEdgeLabel());
// You can access JanusGraphEdge via:
JanusGraphEdge janusGraphEdge = connection.getConnectionEdge();
// Having JanusGraphEdge you can access EdgeLabel directly via:
edgeLabel = janusGraphEdge.edgeLabel();
// You can also access incoming or outgoing vertices of this connection via: connection.getIncomingVertexLabel() or connection.getOutgoingVertexLabel()
});

Related

parameterize examples in cucumber queries

I am new to Cucumber. I have a requirement to use variables instead of actual values in a feature file example. Actual values are to be populated in a separate property file.
Sample feature file:
#tag
Feature: Add an element to stack
The user pushes an element. It gets added to stack
#tag1
Scenario: Push element to empty stack
Given Stack is empty
When User pushes an element
Then stack should have only one element
#tag2
Scenario Outline: Push element to stack
Given Stack has {initial} elements
When User adds {new} element
Then Length of stack increases to {new_size}
| initial | new | new_size |
| 1 | 2 | 2|
| 5 | 9 | 6|
| 0 | 3 | 1|
The output example should be like:
| initial | new | new_size |
| {val1_1} |{val1_2} | {val1_3}|
| {val2_1} |{val2_2} | {val2_3}|
I have used "{}" instead of "<>" as am not able to print elements inside <> in pre-formatted code
Use scenario outlines with examples. Its will solve you data input based queries. For example,
#tag2
Scenario Outline: Push element to stack
Given Stack has <initial> elements
When User adds <new> element
Then Length of stack increases to <new_size>
Examples:
| initial | new | new_size |
| 1 | 2 | 2 |
| 5 | 9 | 6 |
| 0 | 3 | 1 |
And your step definition would be like this,
Given("^Stack has (.*) elements$", (String initial) -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
Similarly do for the other query parameters like (name, new_size).

Non-null and non-undefined type in Flow

Flow defines so called "Maybe types". I.e. ?string is similar to string | null | void (void is a type of value undefined).
Is there something like general type that can be of any value but null and undefined? Basically something like $Diff<$Diff<any, null>, void> if $Diff operator was able to operate on non-object types.
There is no some "magic" type for this, but something like this should work: string | number | boolean | {} | []
It is possible using the NonMaybeType Flow utility type: see $NonMaybeType
$NonMaybeType<T> converts a type T to a non-maybe type. In other words, the values of $NonMaybeType<T> are the values of T except for null and undefined.
// #flow
type MaybeName = ?string;
type Name = $NonMaybeType<MaybeName>;
('Gabriel': MaybeName); // Ok
(null: MaybeName); // Ok
('Gabriel': Name); // Ok
(null: Name); // Error! null can't be annotated as Name because Name is not a maybe type
If you need only a "shallow" type that does not allow null or undefined:
export type NotNullOrUndefined =
| string
| number
| bigint
| []
| {}
Now, in case you want to propagate the not null and not undefined requirement in values nested under objects and arrays you will need the following:
export type NotNullOrUndefined =
| string
| number
| bigint
| NotNullOrUndefined[]
| { [k: string]: NotNullOrUndefined }

Robot framework call soap method with Array parameter

I have a Java Soap service with method
public void helloStudentsName(String[] names)
And user robot framework (SudsLibrary) to call this, because i didn't fine Array in Robot so i use List in code
${names} Create List name1 name2 name3
Call Soap Method helloStudentsName ${names}
I got error
TypeNotFound: Type not found: 'arg0'
And replace $ by # in list declare
#{names} Create List name1 name2 name3
Call Soap Method helloStudentsName #{names}
No error but in Java method receive an empty array.
Can you show me how to call this method?
I think you need to create a special WSDL array object, rather than using a plain robot list. SudsLibrary has a keyword for this, and uses it in an example.
Assuming your WSDL defines a type of ArrayOfString, you might do something like this:
| | ${string array}= | Create Wsdl Object | ArrayOfString
| | Append To List | ${string array} | name1
| | Append To List | ${string array} | name2
| | Append To List | ${string array} | name3
| | ${result}= | Call Soap Method | helloStudentsName | ${string array}
This will only work if your WSDL defines a type of ArrayOfString. Your actual WSDL might call it by some other name.

Find ultimate parent of an entity using recursion in c#

I have an Entity which in turn refers to same table which is its parent. Below is the table which describes it more better.
| ID | Source_ID |
+----+----------+
| 1 | null |
| 2 | 1 |
| 3 | 1 |
| 4 | 2 |
| 5 | 4 |
Now, when I am at ID = 5, I need to fetch its ultimate parent, which is ID = 1.
I tried writing a function which is as below:
<entity> ultimateparententity;
internal <entity> FetchParentComponentRecursive(<entity> entity)
{
if (component.ParentEntity!= null)
{
FetchParentComponentRecursive(entity.ParentEntity);
}
else
{
ultimateparententity = entity;
return component;
}
return entity;
}
I am using variable declared at class level to know the ultimate parent. I am returning variable "Entity" which is never used later, but ultimateparententity is what is used. This approach works, but I am not too happy with this. Any directions will be helpful.
I'm not too familiar with C#, but the general structure of your recursive function looks off.
Try something along the lines of:
internal <entity> FetchParentComponentRecursive(<entity> entity)
{
if (component.ParentEntity == null)
{
return component;
}
else
{
return FetchParentComponentRecursive(entity.ParentEntity);
}
}
By the way, this very much depends on there being no circular references in your data set.

String pointers

Consider the following program (http://play.golang.org/p/IbAstvudtE):
package main
import (
"fmt"
)
func changeStringValueNotOK(dest *string, src string) {
dest = &src
}
func changeStringValueOK(dest *string, src string) {
*dest = src
}
func main() {
a := "Hello"
b := "World"
changeStringValueNotOK(&a, b)
fmt.Println(a) // still "Hello"
changeStringValueOK(&a, b)
fmt.Println(a) // now "World"
}
My goal is to call a function and change the value of string. Works fine with the second function, but not with the first.
Question: what is the meaning of *dest = src compared to dest = &src? I guess the former is "the contents of dest is now src" and the latter is "change the dest variable so that it now points to the address of src" which discards the previous value, but not the contents of a. But even if I am right, I don't understand how the *dest = src works.
I hope my question isn't too fuzzy.
*dest = src
is: Set the value pointed at by dest to the value in src. So it's effective.
dest = &src
is: Set the value of dest to the address of src. As dest is a formal parameter of changeStringValueNotOK the change (to the pointer only, not to the pointee) is visible only locally. As the changed value is not really used, it's total effect is a no operation.
Just to help visualize it graphically, in your main function you have this:
Data Variables
| ... |
-------
| Hello |<----- <a string>
-------
| World |<----- <b string>
-------
| ... |
When you provide the parameters to either of these functions, it becomes:
Data Parameters
| ... |
-------
| Hello |<----- <a string> <----- <dest *string>
-------
| World |<----------------------- <src string>
-------
| ... |
With that scenario, when you do *dest = src, you get:
Data Parameters
| ... |
-------
| Hello | ,- <a string> <---- <dest *string>
------- |
| World |<--/
| |<---------------------- <src string>
-------
| ... |
Note that this effectively changes a itself, so when you return to the prior scope, you'll observe the change.
On the other hand, if you do dest = &src, you'd instead get:
Data Parameters
| ... |
-------
| Hello | <dest *string> ----,
------- |
| World |<---------------------- <src string> <---/
-------
| ... |
Which doesn't solve your problem, because both dest and src are local to the functions they're in.
As a side note, this kind of parameter passing is a common C idiom, but in Go you'd generally change such a string by returning the new value instead.

Resources