How to filter on an object with a list of object - sql

I want to filter on an object which has a field that contains a list of object. Sorry I'm not sure I'm using the right terms, so an example would be better
I have the field shops where I get a list of id and names [{'id':..., 'name':...},{'id':..., 'name':...},...], so I'm trying to do this:
filter(self.id == MyObject.shops.id) or filter(self.id.in_(MyObject.shops.id). Both give me the same results:
AttributeError: Neither 'InstrumentedAttribute'object nor Comparator
object associated with MyObject.shops has an attribute id
What is the right way to do it?

Related

How can I get all of the properties related to one node type?

I have a node Country. I know that this node has some properties, but I don't know which. I mean, I know since I've take a look at model. Here is what I've found in documentation:
Country
name: String
iso_2_code: String
iso_3_code: String
region: String
sub.region: String
I know that if I run
MATCH (c:Country)
RETURN c.iso_2_code
I'll get result for one specific property. Is there a query that would as a result return me something like: name, iso_2_code, iso_3_code, region, sub.region?
If I didn't have access to the model how could I list all of the properties that are attached to some node type?
Answering more from a Cypher or openCypher perspective than for a specific implementation. Using the air-routes dataset. There are three things to consider.
Firstly if you know the properties you want, as you mentioned, you can just ask for them explicitly.
MATCH (a:airport {icao:'KDFW'})
RETURN a.city, a.desc
However, if you want all properties, but do not want to list them all, you can just do:
MATCH (a:airport {icao:'KDFW'})
RETURN properties(a)
If you just want the property keys:
MATCH (a:airport {icao:'KDFW'})
RETURN keys(properties(a))
Lastly, if you want the properties plus the label and ID information you can just do:
MATCH (a:airport {icao:'KDFW'})
RETURN a

How to work with schema returned by 'get_catalog_schema_as_spark_schema'?

Example:
schema = glueContext.get_catalog_schema_as_spark_schema(database=args['Database'], table_name=args['Table'])
if I simply print the returned schema I can see the StructType/StructField structure, something similar to:
StructType(
StructField(column1,StringType,true),
StructField(column2,StringType,true)
)
The object itself is java object and it does not seem to match StructType described in https://github.com/awslabs/aws-glue-libs/blob/master/awsglue/gluetypes.py
if I try to iterate through fields property, it throws error that fields is not iterable.
How do I work with this object? Ideally I want to either be able to convert it into JSON, or atleast get the list of columns.
I appreciate any help here.

How do I make the properties of an anonymous type dynamically change from the user input?

If I Have The following code:
Dim L = From item in _list
Group item By item.Name
Select New With {.Property = Name}
The problem is:
I want to generate a grid based on this grouping, the grouping is specified by the user, so the .Property will be a column name that user specified as the grouping property already I made the Group By depend on the user in my original code, but I could not make the .Property dependent so if the user specify to group the list by Name I want the .Property to be .Name
So, I want to make the .Property determined, any help please?
The fields of anonymous types must be defined at compile-time, so there's not a way to dynamically add fields at run-time. Besides, you wouldn't know what fields are available at compile-time, so you wouldn't to be able to write any code against them.
I would say you should use a different structure to represent the data. A Dictionary is the first type that comes to mind.

AliasToBean DTO with known type

All the examples I am finding for using the AliasToBean transformer use the sessions CreateSqlQuery method rather than the CreateQuery method. They also only return the basic value types, and not any object's of the existing mapped types.
I was hoping it would be possible that my DTO have a property of one of my mapped Domain objects, like below, but I am not getting traction. I get the following exception:
Could not find a setter for property '0' in class 'namespace.DtoClass'
My select looks like the following on my mapped classes (I have confirmed the mappings pull correctly):
SELECT
fcs.MeasurementPoint,
fcs.Form,
fcs.MeasurementPoint.IsUnscheduled as ""IsVisitUnscheduled"",
fcs.MultipleEntryAllowed
FROM FormCollectionSchedule fcs
My end query will be more complex, but I wanted to confirm if this AliasToBean method can return mapped domain objects as well as basic field values from tables retrieved via sql.
the query execution looks like the following:
var result = session.CreateQuery(hqlQuery.ToString())
.SetResultTransformer(NHibernate.Transform.Transformers.AliasToBean(typeof (VisitFormCollectionResult)))
.List<VisitFormCollectionResult>();
note: the VisitFormCollectionResult DTO has more properties, but I wanted to know if I could populate the domain object properties matching the names
update found my problem! I have to explicitly alias each of the fields. once I added an alias, even though the member property on the class matched my DTO's property name, the hydration of the object worked correctly.
The answer to my own question was that each of the individual fields in the select needed an explicit alias matching the property, regardless if the field name already matched the property name of the DTO object:
SELECT
fcs.MeasurementPoint as "MeasurementPoint",
fcs.Form as "Form",
fcs.MeasurementPoint.IsUnscheduled as "IsVisitUnscheduled",
fcs.MultipleEntryAllowed as "MultipleEntryAllowed"
FROM FormCollectionSchedule fcs

Check whether the given object is a list?

How can we check whether the given object is a list or other type
in velocity. In that list i have another list which i need to iterate again.
I also have another data in the parent list which i want to print while iterating parent list. But the problem is the child list object also get printing with actual data. So i want to print the data by checking whether its list or not. Any help is much appreciated.
Before you get any remarks on using too much logic in templates, try this reflection based approach :
velocity (test instanceof)