Iterate through persistentlist hql - sql

I'm trying iterate through persistantlist in HQL. I have persistanlist and each element of list contains another three object. I need to check if name of this object is eq to value.
Acctualy i have done like this:
where object.list[0].name = 'value'
but i want to Iterate list like foreach or something.

Related

How to filter on an object with a list of object

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?

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.

What can I do with the IEnumerable(of T) result except iterate over it?

Ok, I'm new to Linq and I'm using VB.NET. Given a list of objects that has 2 properties called AttributeVariable and AttributeValue, I want to select the AttributeValue for the first item in a collection that has a specific AttributeVariable value. This is my start:
Dim query = From c In items
Where c.AttributeVariable = "thename"
Select c.AttributeValue
Cool, it works and I can for each over the query results and write out the result.
Since c.AttributeValue is a String, what is the simplest way to assign the first item in the list (there is only one) to a string variable?
How about FirstOrDefault? (There is also SingleOrDefault and overloads that take default values; consult the documentation.)
Returns the first element of a sequence, or a default value if the sequence contains no elements.
Then:
Dim attribute = (From c In items
Where c.AttributeVariable = "thename"
Select c.AttributeValue).FirstOrDefault()
The key to this is the attribute value (a String) is selected before the FirstOrDefault - thus the resulting type of the expression is a String.
In any case, while I don't believe it is possible to do this with just query syntax, that does not pose an issue because the (query) returns an IEnumerable which can then be used with a "normal" Enumerable extension method as shown.

Adding Xelement as a Sibling of Xelement without a Parent

I'm trying figure out if this is possible. Basically, I need to create an XElement and then add one or more siblings to that XElement, but without a parent. I'll add that list of XElements to a Parent later, but need some flexibility in building this and other lists of XElements before doing so. Is this possible?
So I would have something like:
Public items As XElement = <ItemA>Something</ItemA>
And then I need to add an element so that the result looks like:
<ItemA>Something</ItemA>
<ItemB>Something Else</ItemB>
That result is what I need to pass around as a single object. I've messed arounnd with IEnumerable(Of XElement), but there is no .Add.
Any thoughts?
then add one or more siblings to that XElement, but without a parent
That's not going to work, elements are only siblings because they share a Parent ...
You'll have to use a temporary parent that you later change or replace.
You can of course use any collection (List<XElement>) to keep a list that you later turn into a list of siblings. Not clear what your problem with that is.

Specifying properties to be updated in linq query

I want to be able to specify the properties to get populated/updated in the linq expression.
Something in the following fashion:
Proxy.UpdateEmployee(List<string> propertiesNames)
Proxy.GetEmployee() //inside the method populate only certain properties
The return values must be of known type(no anonymous types accepted).
DLINQ enable to select by specifying properties' names but the result is IQueryable interface and I'm unable to AsEnumerable() it in order to build the known type query afterwards.
You have to use reflection to modify instance properties by name.
So wherever you're updating your object with LINQ you need to do something like this:
foreach (string propName in propertiesNames)
{
PropertyInfo prop = this.GetType().GetProperty(propName);
prop.SetValue(valueForProp);
}