Alias of an object key using COSMOSDB sql query - azure

I am working with Cosmos DB and I want to write a SQL query that returns different name of an key in document object.
To elaborate, imagine you have the following document in one container having "makeName" key in "make" object.
{
"vehicleDetailId":"38CBEAF7-5858-4EED-8978-E220D2BA745E",
"type":"Vehicle",
"vehicleDetail":{
"make":{
"Id":"B57ADAAD-C16E-44F9-A05B-AAB3BF7068B9",
"makeName":"BMW"
}
}
}
I want to write a query to display "vehicleMake" key in place of "makeName".
How to give alias name in the nested object property.
Output should be like below
{
"vehicleDetailId":"38CBEAF7-5858-4EED-8978-E220D2BA745E",
"type":"Vehicle",
"vehicleDetail":{
"make":{
"Id":"B57ADAAD-C16E-44F9-A05B-AAB3BF7068B9",
"vehicleMake":"BMW"
}
}
}
I have no idea how to query in Cosmosdb to get the above result.

Aliases for properties are similar to the way you'd create a column alias in SQL Server, with the as keyword. In your example, it would be:
SELECT c.vehicleDetail.make.makeName as vehicleMake
FROM c
This would return:
[
{
"vehicleMake": "BMW"
}
]

Try this:
SELECT c.vehicleDetailId, c.type,
{"make":{"Id":c.vehicleDetail.make.Id, "vehicleMake":c.vehicleDetail.make.makeName}} as vehicleDetail
FROM c
It uses the aliasing described in the following documentation. All of the aliasing examples I could find in the documentation or blog posts only show a single level of json output, but it happens that you can nest an object (make) within an object (vehichleDetail) to get the behavior you want.
https://learn.microsoft.com/en-us/azure/cosmos-db/sql-query-aliasing

Related

Getting the vertex and the details of the vertex connected to it

I have a scenario like below, need to get the 'Application' label vertex properties and also, the id or property of the 'work' vertex that is connected to it
I have written the gremlin glv query to get the path and the Application properties, but struggling to get the properties of the vertex connected to it, (using pyton)
the query is,
g.V().hasLabel('Company').outE().inV().hasLabel('Person').outE().inV().hasLabel('Work').outE().inV().hasLabel('Applications').path().unfold().dedup().filter('Applications').elementMap().toList()
this return me the application vertex values like
[{
id:'12159',label:'Applications', 'applicationname':'application1'
},
{
id:'12157',label:'Applications', 'applicationname':'application2'
},
{
id:'12155',label:'Applications', 'applicationname':'application3'
}
]
but we need to get the 'work' vertex details also along with the application details (applications can be connected to multiple work), like,
{
id:'12159',label:'Applications', 'applicationname':'application1', 'workcode':['workcode1', 'workcode2']
},
{
id:'12157',label:'Applications', 'applicationname':'application2', 'workcode':['workcode2']
}.
{
id:'12157',label:'Applications', 'applicationname':'application3', 'workcode':['workcode2']
}
is it possible to get this information in gremlin itself or do we need to use python after getting the path,
the query to add is,
g.addV('Company').as('1').
addV('Company').as('2').
addV('Person').as('3').
addV('Work').as('4').
property(single, 'workcode', 'workcode2').
addV('Work').as('5').
property(single, 'workcode', 'workcode1').
addV('Application').as('6').
property(single, 'applicationname', 'application3').
addV('Application').as('7').
property(single, 'applicationname', 'application2').
addV('Application').as('8').
property(single, 'applicationname', 'application1').
addE('Contractor').from('2').to('3').
addE('Contractor').from('1').to('3').
addE('work').from('3').to('5').addE('work').
from('3').to('4').addE('workingon').from('4').
to('7').addE('workingon').from('4').to('6').
addE('workingon').from('5').to('8').
addE('workingon').from('4').to('8')
thank you
I don't think you should use path step since you are only using the last vertex.
If you want to merge the element map with property from another vertex you can use project:
g.V().hasLabel('Company').outE().inV().
hasLabel('Person').outE().inV().
hasLabel('Work').outE().inV().
hasLabel('Application').dedup().local(union(
elementMap().unfold(),
project('workcose').
by(in().hasLabel('Work').
values('workcode').fold())
).
fold())
example: https://gremlify.com/d5wsk80nm2t/1

Get the Scan Operator when releasing documents

When releasing documents the scan operator should get logged to a file. I know this is a kofax system variable but how do I get it from the ReleaseData object?
Maybe this value is hold by the Values collection? What is the key then? I would try to access it by using
string scanOperator = documentData.Values["?scanOperator?"].Value;
Kofax's weird naming convention strikes again - during setup, said items are referred to as BatchVariableNames. However, during release they are KFX_REL_VARIABLEs (an enum named KfxLinkSourceType).
Here's how you can add all available items during setup:
foreach (var item in setupData.BatchVariableNames)
{
setupData.Links.Add(item, KfxLinkSourceType.KFX_REL_VARIABLE, item);
}
The following sample iterates over the DocumentData.Values collection, storing each BatchVariable in a Dictionary<string, string> named BatchVariables.
foreach (Value v in DocumentData.Values)
{
switch (v.SourceType)
{
case KfxLinkSourceType.KFX_REL_VARIABLE:
BatchVariables.Add(v.SourceName, v.Value);
break;
}
}
You can then access any of those variables by key - for example Scan Operator's User ID yields the scan user's domain and name.

sharepoint 2013 visual studio workflow listitem dynamicvalue - get field value

this is what I did so far:
I'm using LookupSPListItem to get the current listItem out of the currentList.
The Result value is of type DynamicValue.
So far so good.
But how do I access specific values inside the resulting DynamicValue variable?
Unfortunately debugging my workflow doesn't work for some reasons... so I cannot have a look at the variable :(
I do not want to extract every single field on its own... that's too much work.
To access specific properties inside DynamicValue variable depends on the JSON structure it has parsed. But for example if you had something as below:
{
"d" : {
"results" : [
{ "Title" : "Example1" },
{ "Title" : "Example2" }
]
}
}
You can access those using the GetDynamicValueProperty activity (type Microsoft.Activities.dynamicValue) with
PropertyName as "d/results(1)/Title"
Source as your dynamic variable
Result with the variable you want to save the output to.
With the above query it would return Example2. In your case the result will be 1 element array, so you can query for example ID using "d/results(0)/ID"

Call stored procedure with optional parameters using OrmLite

I am using OrmLite to call stored procedure that has optional parameters.
_dbConnection.SqlList<CustomerDTO>("sp_getcustomers #name", new { name = request.Name });
This statement is generating dynamic sql statement with #name as parameter. But I am not knowing how to pass null to this parameter, I tried using DBNull.Value but its not working.
Exception : The given key was not present in the dictionary is raised.
_dbConnection.SqlList<CustomerDTO>("sp_getcustomers #name", new { name = request.Name ?? System.Data.SqlTypes.SqlString.Null});
See these SqlProviderTests for examples of how to effectively make use of OrmLite's Sql* apis.
The right way to call it is with something like:
Db.SqlList<CustomerDTO>("EXEC sp_getcustomers #Name", new { request.Name });
Ormlite has a T4 file to generate C# functions equivalents for the SPs (for SqlServer); the generated files allows you to pass null values.
Support for null parameters in stored procedures was added in commit e6ef83a and released with version 3.9.56 of ServiceStack.OrmLite.

Get all deleted record

I'm looking for a way to get all records where deleted is set to true on a particular table. How might I accomplish this?
Note: Using auto-generated class by SubSonic. Not T-SQL.
The auto-generated SubSonic classes don't support querying logical deletes. But you can do this (version 2.1/2.2 syntax):
public partial class TableClassCollection
{
public TableClassCollection LoadAll(bool suppressLogicalDeletes)
{
SubSonic.SqlQuery q = new SubSonic.Select(TableClass.Schema)
.From(TableClass.Schema);
if (suppressLogicalDeletes)
{
q.Where(TableClass.DeletedColumn).IsEqualTo(false);
}
return q.ExecuteAsCollection<TableClassCollection>();
}
}
More examples at subsonicproject.com
I've never heard of SubSonic before, but a quick Google search turned up: Select Queries in SubSonic.
So, using that page as a guide, it sounds like you'd be able to write your query as:
FooCollection deletedFoos = // use the generated collection class
DB.Select().From("FooTable") // table name goes here
.Where("deleted").IsEqualTo(true) // might need 1, depends on database?
.ExecuteAsCollection<FooCollection>(); // should match the type above
not a lot of detail in your question, but assuming there's a column named "deleted," it would look something like this:
select * from tableName where deleted = true

Resources