Currently am working in NEO4J and iam new in graph db. Now i need to paginate the records from graph db. And i created the following query
MATCH (n:Question)<-[r1:HAS_QUESTION]-(c:Chapter)
MATCH (c)-[r2:HAS_CHILD]->(t:Topic)-[r3:HAS_QUESTION]->(qstn:Question)
WHERE ID(c)=330
WITH n,qstn WHERE NOT(n:Removed) AND NOT(qstn:Removed)
WITH n,qstn
RETURN n as Question,qstn
In this query i got 13 question nodes. But when i add skip and limit to that query , i got only 7 nodes instead of 10. The querys is
MATCH (n:Question)<-[r1:HAS_QUESTION]-(c:Chapter)
MATCH (c)-[r2:HAS_CHILD]->(t:Topic)-[r3:HAS_QUESTION]->(qstn:Question)
WHERE id(c)=330 WITH n,qstn
WHERE NOT(n:Removed) AND NOT(qstn:Removed)
WITH n,qstn
RETURN n as Question,qstn
SKIP 0 LIMIT 10;
Somebody please explain what is happening with this query. Is there any idea to get the 10 nodes.
The query for the sample graph is the following.
CREATE (c:Chapter {chapter_name:"Biodiversity and Conservation"})
CREATE (t:Topic {topic_name:"Biodiversity Conservation"})
CREATE (q:Question {content: "first question"})
CREATE (t1:Topic {topic_name:"Biodiversity"})
CREATE (q1:Question {content: "second question"})
CREATE (q0:Question {content: "third question"})
CREATE (q01:Question {content: "fourth question"})
CREATE (q2:Question {content: "fifth question"})
CREATE (q3:Question {content: "sixth question"})
CREATE (q4:Question {content: "seventh question"})
CREATE (q5:Question {content: "eighth question"})
CREATE (q6:Question {content: "nineth question"})
CREATE (q7:Question {content: "tenth question"})
CREATE (q8:Question {content: "eleventh question"})
CREATE (q9:Question {content: "twelfth question"})
CREATE (q10:Question {content: "thirteenth question"})
CREATE (q11:Question {content: "fourteenth question"})
CREATE (q12:Question {content: "fifteenth question"})
CREATE (q13:Question {content: "sixteenth question"})
CREATE (c)-[r:HAS_TOPIC]->(t)
CREATE (c)-[r1:HAS_TOPIC]->(t1)
CREATE (t)-[r2:HAS_QUESTION]->(q)
CREATE (t1)-[r3:HAS_QUESTION]->(q1)
CREATE (c)-[r4:HAS_QUESTION]->(q0)
CREATE (c)-[r5:HAS_QUESTION]->(q01)
CREATE (c)-[r6:HAS_QUESTION]->(q2)
CREATE (c)-[r7:HAS_QUESTION]->(q3)
CREATE (c)-[r8:HAS_QUESTION]->(q4)
CREATE (c)-[r9:HAS_QUESTION]->(q5)
CREATE (c)-[r0:HAS_QUESTION]->(q6)
CREATE (c)-[r11:HAS_QUESTION]->(q7)
CREATE (c)-[r12:HAS_QUESTION]->(q8)
CREATE (c)-[r13:HAS_QUESTION]->(q9)
CREATE (c)-[r14:HAS_QUESTION]->(q10)
CREATE (c)-[r15:HAS_QUESTION]->(q11)
CREATE (c)-[r16:HAS_QUESTION]->(q12)
CREATE (c)-[r17:HAS_QUESTION]->(q13)
return c,t,t1,q0,q01,q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,q13,r,r1,r2,r3,r4,r5,r6,r7,r8,r9,r0,r11,
r12,r13,r14,r15,r16,r17
Which version do you use?
Can you share your graph so that we can reproduce the issue?
I simplified your query, could you try this one?
MATCH (n:Question)<-[:HAS_QUESTION]-(c:Chapter)
WHERE id(c)=330 AND NOT(n:Removed)
MATCH (c)-[:HAS_CHILD]->(t:Topic)-[:HAS_QUESTION]->(qstn:Question)
WHERE NOT(qstn:Removed)
RETURN n,qstn
SKIP 0 LIMIT 10;
I simplified my query in the following way.. Now it is working without any problem
START c = node({chapter_id})
OPTIONAL MATCH c-[r*..2]->(n:Question)
WHERE NOT(n:Removed)
RETURN DISTINCT n SKIP 0 LIMIT 10;
Related
Is it possible to easily see which roles have access to which script deployments?
I tried making a script deployments saved search as well as a role saved search but could not really find out how to extract this information.
Does anyone know?
I cannot see a way to complete this in the UI/via saved search. You can complete this via suitescript however by following this sort of layout. You can schedule the script to run periodically, or just run in the browser console to get the data you want. You can also add code to create an excel file to easily digest the information...
Layout in SS2.0
//gather all applicable role ids
var Roles = [];
//gather all applicable script deployment ids
var ScriptDep = [];
//for each script deployment id get the "Roles" from the "Audience" tab in the UI
for (var i=0; i<ScriptDep.length; i++){
var script = record.load({
type: 'scriptdeployment',
id: ScriptDep[i]
});
var scriptAudienceField = script.getField({
fieldId: 'audslctrole'
});
var scriptAudience = scriptAudienceField.getSelectOptions({
filter : '*',
operator : 'contains'
});
var RoleID = ; //role ID you care about, maybe loop through all roles with Roles[j]
var test = scriptAudience.includes(RoleID); //returns true or false this deployment is deployed to this role
}
Suite Answer 86327 gives the dollowing SS1.0 sample code
var search = nlapiLoadSearch('scriptdeployment', 147); //load search of all script deployments
var resultSet = search.runSearch();
resultSet.forEachResult(function(searchResult){ //for each script deployment returned by the search, get the id
var record = nlapiLoadRecord('scriptdeployment', searchResult.id); //load the script deployemnt
var arrayOfRoles = record.getFieldValues('audslctrole'); //get the values of the "Roles" from the "Audience" tab in the UI
if(arrayOfRoles == '18'){ //change based on the internal ID of the role
console.log(searchResult.id);
};
return true;
});
I have a process being executed in a Map/Reduce script which creates a bunch of quotes.
I would like to be able to add the Map/Reduce task ID to a field on the Quote/Estimate record.
The question therefore... is there a way to access the actual current task ID from within the M/R Script itself.
It would look something like: MAPREDUCETASK_02686f177c0a7667707763070b7c7752500068061c10016f1c470041_dc257c953b420bea6b7
Even though Task ID is not directly accessible from the script context (as it was already mentioned by ehcanadian), it can be obtained through Scheduled Script Instance search triggered from within the map/reduce script.
Example:
const _getCurrentTaskId = () => {
let scriptObj = runtime.getCurrentScript();
let scriptId = scriptObj.id;
let scriptDeploymentId = scriptObj.deploymentId;
let mapReduceTaskSearch = search.create({
type: search.Type.SCHEDULED_SCRIPT_INSTANCE,
filters: [
['status', 'anyof', 'PROCESSING'],
'AND',
['script.scriptid', 'is', scriptId],
'AND',
['scriptdeployment.scriptid', 'is', scriptDeploymentId]
],
columns: [
'taskid'
]
});
let taskId;
mapReduceTaskSearch.run().each(function(result) {
taskId = result.getValue('taskid');
});
return taskId;
}
Please note that if you have more SuiteCloud processors and running the same script deployment in parallel, this solution won't work (as it may return Task IDs of other currently running script deployments).
For MR you can get (and set) script ID and deployment ID, and ID of each task you ran from map/shuffle/reduce stages.
There isn't a method to get the currently executing M/R's task ID from within the M/R itself, as it's not exposed via the context. However, you could store that value in a custom record to be retrieved within the executing M/R if you're executing the M/R via script. (Checking script ID and deployment ID.) It won't be failsafe if you're executing more than one M/R of the same script though.
I would like to create a query which returns all the Requests (asset) in which the Container's (asset) owner's id is equal to the parameter.
Model file (owner of a container is a Company participant, identified by id):
namespace org.acme.shipping.assets
import org.acme.shipping.participants.*
asset Container identified by number {
o String number
o ContainerType type
o String content
o ContainerStatus status default = "FREE"
--> Company owner
}
enum ContainerType {
o DRY
o REEFER
}
enum ContainerStatus {
o LOCKED
o FREE
}
asset Request identified by id {
o String id
--> Container container
}
Query file
query getRequestsByCompany {
description: "Get requests by company"
statement:
SELECT org.acme.shipping.assets.Request
WHERE (container.owner.id == _$company_id)
}
However, the current query does not seem to work. Is this achievable with a query?
I did a lot of research also to do it using query file, but couldnt find a way, so I think that its not possible at moment.
The alternative way is to use loopback filters:
https://github.com/hyperledger/composer-knowledge-wiki/blob/latest/knowledge.md#information_source--filters-loopback
https://loopback.io/doc/en/lb2/Where-filter.html
Something like:
{"where":{"shipmentId":1000}, "include":"resolve"}
you can go one level in like search by number . I am working on it if get the exact solution .
query getRequestsByCompany {
description: "Get requests by company"
statement:
SELECT org.acme.shipping.assets.Request
WHERE (container == _$container)
}
I am trying to insert data in azure easy table.
But in New Azure portal, I don't know where to write my insert script.
Its very easy ..check below sample code
table.insert(function insertData(item) {
console.log("item............."+item);
var tempvari = item.execute();
console.log("tempvari......................." + tempvari);
return tempvari;
});
I want to create a stored procedure in DocumentDB and use it whenever I need later on. To execute a stored procedure I need to know a storedProcedureLink. When I register stored procedure with CreateStoredProcedureAsync method I get the link, am I supposed to store this link somewhere myself if I want to execute this stored procedure later? Can I execute a stored procedure if all I know is a procedure name? From all the examples I found it seems that I need to create and register stored procedure right before I need to execute it, is it the case?
You can absolutely create the Stored Procedure beforehand and have it saved on the server for future use. You do not need to create it just before using it. This was for sample purposes only. We expect the majority of the time that the stored procedures will exist already and you just use them in your application.
You do need the SelfLink to execute the Stored Procedure.
One way to get this would be to query for the Stored Procedure (by Name), get the SelfLink and then use that to execute the stored procedure.
Querying for a Stored Procedure by name would look something like;
StoredProcedure sproc = client.CreateStoredProcedureQuery(collection.StoredProceduresLink, "select * from root r where r.id = \"sproc name\"");
The resulting sproc variable will contain the SelfLink of the stored procedure you want to execute.
var result = client.ExecuteStoredProcedureAsync(sproc.SelfLink);
For comprehensive samples of how to work with Stored Procedures please see the DocumentDB.Samples.ServerSideScripts project in the samples posted at;
http://code.msdn.microsoft.com/Azure-DocumentDB-NET-Code-6b3da8af
From all the examples I found it seems that I need to create and register stored procedure right before I need to execute it, is it the case?
No. Stored procedure creation and registration does not have to happen during execution.
The samples are educational, but do not offer real-world patterns. See the DocumentManagement basic CRUD operations. Samples also assume a single collection too. See the Partitioning basic CRUD operations.
While I applaud the DocumentDB adaption of SQL coding conventions, the usage pattern currently falls short for .NET developers. The decade old pattern of creating CRUD stored procedures in SQL Server and then calling them by name via ADO.NET or a TableAdapter in a DataSet does not work in the DocumentDB.
Can I execute a stored procedure if all I know is a procedure name?
Yes, but it's not pretty:
StoredProcedure storedProcedure = this.DocumentClient.CreateStoredProcedureQuery(new Uri(collection.StoredProceduresLink)).Where(p => p.Id == "GetPunkRocker").AsEnumerable().FirstOrDefault();
When using a PartitionResolver, things get more complicated:
public async Task<PunkRocker> GetPunkRockerAsync(string partitionKey)
{
foreach (string collectionLink in this.PartitionResolver.ResolveForRead(partitionKey))
{
DocumentCollection collection = this.DocumentClient.CreateDocumentCollectionQuery(new Uri(this.Database.SelfLink)).Where(c => c.SelfLink == collectionLink).AsEnumerable().FirstOrDefault();
if (collection == null)
{
// Log...
continue;
}
StoredProcedure storedProcedure = this.DocumentClient.CreateStoredProcedureQuery(new Uri(collection.StoredProceduresLink)).Where(p => p.Id == "GetPunkRocker").AsEnumerable().FirstOrDefault();
if (storedProcedure == null)
{
// Log...
continue;
}
PunkRocker punkRocker = await this.DocumentClient.ExecuteStoredProcedureAsync<PunkRocker>(new Uri(storedProcedure.SelfLink), partitionKey);
if (punkRocker != null)
{
return punkRocker;
}
}
return null;
}
Just tried this approach and it does not work.
client.CreateStoredProcedureQuery( link, String.Format( "select * from root r where r.id = '{0}'", "spname1" ) ).ToList( ).FirstOrDefault( );
returns null
client.CreateStoredProcedureQuery( link, String.Format( "select * from root r" ) ).ToList( ).FirstOrDefault( );
returns correct stored procedure
{
"id": "spname1",
"body": "function() {
var context = getContext();
var collection = context.getCollection();
}",
"_rid": "XXX",
"_ts": 1410449011.0,
"_self": "XXX",
"_etag": "XXX"
}
You can look for the SP in the DB first in .NET SDK
StoredProcedure storedProcedure = Client.CreateStoredProcedureQuery(GetCollection(eColl).SelfLink).Where(c => c.Id == "SP name").AsEnumerable().FirstOrDefault();
It appears that Microsoft is now providing a few samples on how to execute stored procedures:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.documents.client.documentclient.executestoredprocedureasync?view=azure-dotnet